0

Can someone show me a code to update a enterprise resource custom field with lookup table ? Already ran the internet looking for some sample code but did not succeed.

1 Answers1

0

You can create and update a custom field with a lookup table using the below code . But we can not update or delete builtin custom fields

var projContext = new ProjectContext(projectServerUrl);

CustomFieldCollection CustomField = projContext.CustomFields;
EntityTypes Entitytype = projContext.EntityTypes;
LookupTableCollection lookupTables = projContext.LookupTables;
projContext.Load(CustomField);
projContext.Load(Entitytype);
projContext.Load(lookupTables);
projContext.ExecuteQuery();

CustomFieldCreationInformation NewfieldInfo = new CustomFieldCreationInformation();
NewfieldInfo.Id = new Guid();
NewfieldInfo.Name = "The Name";
NewfieldInfo.Description = "The Description";
NewfieldInfo.IsWorkflowControlled = true;
NewfieldInfo.IsRequired = true;
NewfieldInfo.IsEditableInVisibility = false;
NewfieldInfo.IsMultilineText = false;

LookupTable lookuptable = lookupTables.ToList().Find(x => x.Name == "LookupTableName");
projContext.Load(lookuptable);
projContext.ExecuteQuery();
NewfieldInfo.LookupTable = lookuptable;

NewfieldInfo.EntityType = Entitytype.ProjectEntity;
NewfieldInfo.FieldType = CustomFieldType.TEXT;

projContext.CustomFields.Add(NewfieldInfo);
projContext.CustomFields.Update();
projContext.ExecuteQuery();
Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Darshani Jayasekara
  • 561
  • 1
  • 4
  • 14