none
Create/Edit resource engagements using JSOM

    Pertanyaan

  • Hi,

    Can someone help me in understanding how do i create/edit engagements using Project Online JSOM.

    I tried below for editing the engagements

    var projectEngagment; function getProjectEngagements(project){

    //Just to filter an Project if(project.get_id() == "c4aa146b-e759-e811-80ce-00155d24aa3d"){ alert(project.get_name()); projectEngagment = project.get_engagements(); projContext.load(projectEngagment,'Include(Id, Description)'); projContext.executeQueryAsync(onEngagementsSuccess, onQueryFailed); } } function onEngagementsSuccess(sender, args){ for(var i=0;i<projectEngagment.get_data().length;i++){ projectEngagment.get_data()[i].set_description("editing with JSOM"); } //projectEngagment.get_data()[0].get_description(); var updateJob = projectEngagment.update(); projContext.waitForQueueAsync(updateJob, 10, function(){ alert("Completed"); }); }


    To get Projects i have referenced: https://docs.microsoft.com/en-us/office/client-developer/project/create-retrieve-update-delete-projects-using-project-server-javascript#prerequisites-for-working-with-project-server-2013-projects-in-the-javascript-object-model

    12 Juni 2018 19:20

Semua Balasan

  • Hello, have you seen the API details here: https://msdn.microsoft.com/en-us/office/project/api/index Engagement creation here: https://msdn.microsoft.com/en-us/office/project/api/engagementcreationinformation Paul

    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    13 Juni 2018 6:20
    Moderator
  • Thank you for replying @PWMather.

    I did try earlier with that link... Here is my example:

    	 function addProjectEngagementNew(projUid){
            //http://contoso.sharepoint.com/sites/pwa/api/ProjectServer/Projects('{projectid}')/Engagements/Add
            //{Res: "GUID", Proj: "GUID", Start: Fri Jun 08 2018 13:30:00 GMT+0530 (India Standard Time), Finish: Fri Jun 08 2018 22:30:00 GMT+0530 (India Standard Time), Units: 10000}
    
            postData = {"parameters":{
                'ResourceId': "<<GUID>>",
                'Finish': '6/8/2018',
                'Start': '6/8/2018',
                'MaxUnits': '10000'
            }};
      
    		$.ajax({
    			url: PWA_SITE + "/_api/ProjectServer/Projects('"+projUid+"')/Engagements",
    			type: "post",
    			data: postData,
    			contentType: "application/json",
    			dataType: 'json',
    			headers: {
    				"Accept": "application/json;odata=verbose",				
    			},
    			success:function(data1){
    				console.log(data1);
    			},
    			error: function(xhr, errmsg, errno){
    				alert(errmsg);
    			}
    		});        
        }


    Error which i received when i used POST RestFul API :

    {"error":{"code":"-2130575251, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again."}}}

    I did tried to keep the security related stuff in header like below:

    postData = {"parameters":{
                'ResourceId': "<<RES_UUID>>",
                'Finish': '6/8/2018',
                'Start': '6/8/2018',
                'MaxUnits': '10000'
            }};
            $.ajax({
                url: PWA_SITE + "/_api/contextinfo",
                method: "POST",
                headers: { "Accept": "application/json; odata=verbose" }
            }).then(function(data){          
                console.log(data)  ;
                $.ajax({
                    url: PWA_SITE + "/_api/ProjectServer/Projects('"+projUid+"')/Engagements",
                    type: "post",
                    data: postData,
                    contentType: "application/json",
                    dataType: 'json',
                    headers: {
                        "Accept": "application/json;odata=verbose",
                        "X-RequestDigest": data.d.GetContextWebInformation.FormDigestValue
                    },
                    success:function(data1){
                        console.log(data1);
                    },
                    error: function(xhr, errmsg, errno){
                        alert(errmsg);
                    }
                });
            });

    Error Response:

    {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid JSON. A token was not recognized in the JSON content."}}}


    14 Juni 2018 5:53