Asked by:
How do update multiple custom field in Microsoft Project Server using CSOM

Question
-
I am updating Multiple custom field Request Type and Department, Only last value(Department) is updating Please some one guide me where i am doing mistake. Below is My code snippet
DraftProject projCheckedOut = null;
try
{
Dictionary<string, object> projDict = new Dictionary<string, object>();
MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper(PWAUrl, UserName, Password);
using (ProjectContext projContext = new ProjectContext(PWAUrl))
{
projContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
var PrjList = projContext.LoadQuery(projContext.Projects.Where(proj => proj.Id == ProjectId));
projContext.ExecuteQuery();
Guid pGuid = PrjList.First().Id;
PublishedProject proj2Edit = PrjList.First();
projCheckedOut = proj2Edit.CheckOut().IncludeCustomFields;
projContext.Load(projCheckedOut);
projContext.ExecuteQuery();
var cflist = projContext.LoadQuery(projContext.CustomFields.Where(cf => cf.Name == "Request Type"));
projContext.ExecuteQuery();
projCheckedOut.SetCustomFieldValue(cflist.FirstOrDefault().InternalName, new[] { "Entry_6a51155570f5e51180d000155dd43708" });
cflist = projContext.LoadQuery(projContext.CustomFields.Where(cf => cf.Name == "Department"));
projContext.ExecuteQuery();
projCheckedOut.SetCustomFieldValue(cflist.FirstOrDefault().InternalName, new[] { "Entry_0a3970a471f5e51180cc00155dd45b0a" });
QueueJob qJob = projCheckedOut.Publish(true);
JobState jobState = projContext.WaitForQueue(qJob, 70);
}
}
catch (Exception ex)
{
}- Edited by Prasanna Joshi Tuesday, April 12, 2016 6:44 AM
Monday, April 11, 2016 10:46 AM
All replies
-
What happens if you comment the code where you update "Department"? Are you able to update the first custom field then? I am having a similar problem where the first custom field is not being updated.
Also clean up your code a bit.
Here are two articles that may help you:- http://www.jonashendrickx.com/2016/04/11/update-customfield-based-on-lookuptable-value/
- http://www.jonashendrickx.com/2016/03/31/authenticating-with-csom-in-project-server-part-2/
I created this to make my code compatible with both Project Server Online and Project Server On-Premises.
Jonas Hendrickx If I helped you, mark my answer as helpful.
Tuesday, April 12, 2016 10:07 AM -
Thanks Jonas Hendrickx , yes if i commented Department then first column is updating. I followed the link which you forwarded still am getting same result, Only last column is updating. Can u please help me with code snippet.
prasanna
Wednesday, April 13, 2016 1:30 PM -
Have you tried doing a:
projCheckedOut.Update() prior to the publish?
Friday, May 13, 2016 4:07 PM -
After each SetCustomFieldValue call, you need to run the update method on the draft project object. For example:
At the end of all the field updates, you only need to run the Publish method once.projCheckedOut.SetCustomFieldValue(cflist.FirstOrDefault().InternalName, new[] { "Entry_6a51155570f5e51180d000155dd43708" });
QueueJob qJob = projCheckedOut.Update();
JobState jobState = projContext.WaitForQueue(qJob, 1000);
projCheckedOut.SetCustomFieldValue(cflist.FirstOrDefault().InternalName, new[] { "Entry_0a3970a471f5e51180cc00155dd45b0a" });
QueueJob qJob = projCheckedOut.Update();
JobState jobState = projContext.WaitForQueue(qJob, 1000);
- Edited by Richard Smairat Friday, March 31, 2017 4:42 AM
- Proposed as answer by Richard Smairat Friday, March 31, 2017 5:13 AM
Friday, March 31, 2017 4:36 AM -
Hi,
Update custom field as values as below and then write update/publish statements.
projCheckedOut[internalName1] = "value";
projCheckedOut[internalName2] = "Your value";
.
.
// then your update statements. QueueJob qJob = projCheckedOut.Publish(true);
QueueJob qJobUpdate = projContext.Projects.Update();
JobState jobState = projContext.WaitForQueue(qJobUpdate , 70);Thanks, Ram
Thursday, May 2, 2019 10:10 AM