none
Unable to Update Project Level Custom Field using CSOM RRS feed

  • Question

  • Hi,

    I have started using CSOM for my Project Online and I could successfully Read and Create Project. But was wondering how to update project level customfields. Following is my code for the same. Please let me know where I am making mistake.

     var PrjList = projContext.LoadQuery(projContext.Projects.Where(proj => proj.Name == "HelloWorld"));
                    projContext.ExecuteQuery();
                    Guid pGuid = PrjList.First().Id;
    
                    Project p = projContext.Projects.GetByGuid(pGuid);
    
                    var cfList = projContext.LoadQuery(p.CustomFields.Where(cf => cf.Name == "MyTest"));
                    projContext.ExecuteQuery();
    
                    CustomField c = projContext.CustomFields.GetByGuid(cfList.First().Id);
    
                    p.SetCustomFieldValue("MyTest", "HIIIIIIIII");
                    p.CustomFields.Update();


    Thanks, Parth

    Friday, June 21, 2013 12:04 PM

All replies

  • Does anyone has any idea on how to Update Customfield using CSOM ?

    Thanks, Parth

    Monday, June 24, 2013 7:19 AM
  • Hi,

    Till now, what I have figured out is,

    I am able to update the Project Information But not the Custom Fieds. Below is the code which updates the Custom fields and Project Information.

     var PrjList = projContext.LoadQuery(projContext.Projects.Where(proj => proj.Name == "HelloWorld"));
                    projContext.ExecuteQuery();
                    Guid pGuid = PrjList.First().Id;
    
                    PublishedProject proj2Edit = PrjList.First().IncludeCustomFields;
                    DraftProject projChechedOut = proj2Edit.CheckOut().IncludeCustomFields;
                    projContext.ExecuteQuery();
    
                    //var cfList = projContext.LoadQuery(projChechedOut.CustomFields.Where(cf => cf.Name == "Mytest"));    
                    projChechedOut.SetCustomFieldValue("MyTest", "Hello");
                    projChechedOut.StartDate = DateTime.Now.AddDays(15);
                    projChechedOut.Description = "This is the New Description" + DateTime.Now.ToShortTimeString();
                    
                    QueueJob qJob = projChechedOut.Publish(true);
                    JobState jobState = projContext.WaitForQueue(qJob, timeoutSeconds);

    Any Ideas?


    Thanks, Parth

    Thursday, June 27, 2013 4:16 PM
  • Please help!!

    Thanks, Parth

    Tuesday, July 2, 2013 7:23 AM
  • Hi,

    The problem you have is in the first parameter to SetCustomFieldValue(fieldName, newValue), you need to use the InternalName of the field.

    The lack of MSDN documentation on this one prompted me to blog about it:

    http://nearbaseline.com.au/blog/2013/08/updating-project-server-custom-fields-via-jsom-csom/

    HTH,


    Martin Laukkanen (Project Server Blog - www.nearbaseline.com/blog)

    Wednesday, August 7, 2013 4:39 AM
  • yes you can update custom field using csom 

    DraftProject projCheckedOut = pubProj.CheckOut();
                        projCheckedOut.Name = "Project Name";
                        projCheckedOut.Description = "This content updated by ProjectServerCode";
                        projCheckedOut.SetCustomFieldValue("Custom_b50f29a9881de61180d700155d1c581a", "CustoFieldValue");
                        //Note:Custom_b50f29a9881de61180d700155d1c581a=Custom_(Your Custom Field GUID without hyphen)
                        projCheckedOut.Update();
                        ProjectCont.Load(projCheckedOut);
                        projCheckedOut.Publish(true);
                        ProjectCont.ExecuteQuery();
                        ProjectCont.Projects.Update();
                        ProjectCont.ExecuteQuery();
                        projCheckedOut.Publish(true);
    Follow link to complete code
    Update Custom Field Value Using CSOM


    anil gangwar

    Tuesday, June 7, 2016 7:22 AM