none
how to create engagements with CSOM RRS feed

  • Question

  • the new CSOM version contains class to create engagements, but there are no examples of how to actually create them

    https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-august-2016

    does anyone tried to create them and if so can you please provide an example? i see an engagement being created , but its empty

    this is what i got 


                        foreach (EnterpriseResource e in projectList)
                                            {
                                                if (e.Id == entResUid)
                                                {
                                                    assignToTeam(projContext, projectGuid, e, draft);

                                                     ProjectEngagementCreationInformation pe = new ProjectEngagementCreationInformation();
                                                    pe.Id = new Guid();
                                                    pe.Resource = e;
                                                    pe.Description = "test";
                                                    pe.Start = DateTime.Now;
                                                    pe.Finish = DateTime.Now;
                                                    pe.MaxUnits = 10;

                                                    draft.Engagements.Add(pe);
                                                                                                 
                                                    Console.WriteLine("Assigned to team " + e.Name);
                                                    
                                                    draft.Update();
                                                    projContext.Load(draft);
                                                    projContext.ExecuteQuery();
                                                    QueueJob qJob = projContext.Projects.Update();
                                                    projContext.ExecuteQuery();
                                                     
                                                }
                                            }


    tatiana



    Monday, November 7, 2016 5:45 PM

All replies

  • I hope you are aware around Project server CSOM model. This engagement class is specific to project server and once you execute the call, it will setup a new engagement. I could not find the class details published on MSDN yet.

    Thanks, Ashish | Please mark a post helpful/answer if it is helpful or answer your query.

    Tuesday, November 8, 2016 11:13 AM
  • I'd rather do not risk)
    Tuesday, November 8, 2016 11:30 AM
  • Hi Any updates on this. 

    I have Code which adds the resource to the Project But could not see the Units updating....


    Thanks, Parth

    Thursday, December 22, 2016 8:11 AM
  • Did anyone have a working example of this - creating a resource engagement with CSOM - that they could post?

    Thanks

    Tuesday, September 19, 2017 6:12 PM
  • I figured out the issue with adding the engagement.

    Afterwards, you have to call Update() on the EngagementCollection, not the draft project.

    IE instead of

    draftProject.Update();

    do this

    draftProject.Engagements.Update();

    then publish, checkin, and so on.

    Tuesday, September 19, 2017 11:30 PM
  • Just to muddy the waters some more, following my instructions above to update the engagements collection when adding a new engagement works - but the engagements have a status of 'Draft'. you won't see them appear in the resource requests view. Publishing the project doesn't publish the engagements in the draft project. And, you can't set the Status of the engagement when you are creating the ProjectEngagementCreationInformation object. What you have to do is, after adding the new engagement and updating the engagements like I outlines above, you then need to get the engagements that are Status=Draft and change the status to Proposed, like this:

     var draftEngagements = ctx.LoadQuery(draftProject.Engagements
                                .IncludeWithDefaultProperties(_ => _.Status))
                                .Where(_ => _.Status == EngagementStatus.Draft );
    ctx.ExecuteQuery();
    foreach (var engagement in draftEngagements)
    {
            engagement.Status = EngagementStatus.Proposed;
    }
    draftProject.Engagements.Update();

    And only then will you see the engagements show up as a proposed resource engagement request.

    Wednesday, September 20, 2017 3:25 AM
  • Hi,

    To complete the precious answer given by David, here is a complete CSOM code  which creates engagement on a project, for a specified resource.

    Nothing new compared to David's explanations, but maybe having everything in a single function could help.

    I want to thank David for his post, espacially for the switch from Draft to Proposed : well done ;-)

            public static void CreateEngagement(string ResID,  string prjID, double newWork)
            {
                List<Engagement> engagements = new List<Engagement>();
                if (ResID == null || prjID == null)
                    return;
                if (ResID == "" || prjID == "")
                    return ;
    
                prj.ProjectContext prjContext = HTTPClientSPOnline.CreateCSOMContest();
                prj.DraftProject dp = prjContext.Projects.GetById(prjID).CheckOut(); 
                var resource = prjContext.EnterpriseResources.GetById(ResID);
                prjContext.Load<prj.EnterpriseResource>(resource);
    
                prj.ProjectEngagementCreationInformation engi = new prj.ProjectEngagementCreationInformation();
                engi.Description = "Create from CSOM at "+DateTime.Now.ToString();
                engi.Work = "65h";
                engi.Start = DateTime.Now;
                engi.Finish = DateTime.Now.AddMonths(1);
                engi.Resource = resource;
                engi.Id = Guid.NewGuid();
                
             
                //engi.MaxUnits = 1;
                //engi.WorkTimeSpan = TimeSpan.FromDays(15);
                prjContext.Load<prj.DraftProject>(dp);
                prjContext.Load(dp.Engagements);
                prjContext.ExecuteQuery();
    
                dp.Engagements.Add(engi);
                dp.Engagements.Update();
                var job = dp.Update();
               // prjContext.ExecuteQuery();
                prjContext.WaitForQueue(job, 10000) ;
    
    
                prjContext.Load(dp.Engagements);
                var e = dp.Engagements.GetById(engi.Id.ToString());
                prjContext.Load<prj.ProjectEngagement>(e);
                prjContext.ExecuteQuery();
                
                if (e.Status == prj.EngagementStatus.Draft)
                    e.Status = prj.EngagementStatus.Proposed;
                dp.Engagements.Update();
                job = dp.Update();
                prjContext.WaitForQueue(job, 10000);
                job = dp.Publish(true);
                prjContext.WaitForQueue(job, 10000);
    
            }
    

    The code for ProjectContext creation is just there, Nothing special I guess, but in case…Of course you can put it where you want, in your class or a helper/dataaccess class.

            public static ProjectContext CreateCSOMContest()
            {
                ProjectContext prjContext = new ProjectContext(SPSite);
    
                //Creating Credentials 
                var passWord = new SecureString();
                foreach (var c in PWD) passWord.AppendChar(c);
                var credential = new SharePointOnlineCredentials(USER, passWord);
                prjContext.Credentials = credential;
                return prjContext;
            }

    Tuesday, June 5, 2018 8:59 AM
  • Hi Guys,

    Can someone provide REST API  + Payload for the same functionality  ? or may be JSOM sample.


    Thanks, Parth

    Monday, July 23, 2018 4:51 AM