Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

CSOM - create new custom field row

$
0
0

can anyone provide an example of how to create a new custom field row by using SCOM? 

i am trying to update Enterprise Resources custom fields and the code that i already have works fine for custom fields where row already exists, but doesnt work for new resources where a new custom field row needs to be created. 

CustomFieldCollection customFields = projContext.CustomFields;
EnterpriseResourceCollection resources = projContext.EnterpriseResources;

projContext.Load(projContext.EnterpriseResources.GetByGuid(rs.Id));
projContext.ExecuteQuery();

projContext.Load(rs);
projContext.Load(rs.CustomFields);

projContext.ExecuteQuery();

CustomField cfPersonType;

String cfPersonTypeInternalName;

cfPersonType = customFields.First(c => c.Name == "Resource_HR_Person_Type");
cfPersonTypeInternalName = cfPersonType.InternalName;

rs[cfPersonTypeInternalName] = "Custom Field Value Here";   //update existing row with new value

  resources.Update();
projContext.ExecuteQuery();

if the row doesn't exist, i am getting the following error. 



tatiana



Viewing all articles
Browse latest Browse all 5347

Trending Articles