/// <summary> /// Create a simple lookup table with 3 text value choose (one/two/three) /// </summary> /// <returns></returns> private static csom.LookupTable CreateSimpleLookupTable() { string[] lookupValues = new string[] { "one", "two", "three" }; csom.LookupTable lookupTable = context.LookupTables.Add(new csom.LookupTableCreationInformation() { Name = "Simple lookup table", SortOrder = csom.LookupTableSortOrder.Ascending, Entries = lookupValues.Select((val, i) => new csom.LookupEntryCreationInformation() { Value = new csom.LookupEntryValue() { TextValue = val }, SortIndex = i }).ToArray(), Masks = new csom.LookupMask[] { new csom.LookupMask() { MaskType = csom.LookupTableMaskSequence.CHARACTERS, Length = 0, Separator = "." } } }); context.LookupTables.Update(); context.ExecuteQuery(); return(lookupTable); }
/// <summary> /// Create Project/Task/Resource custom fields. Field type will be TEXT. /// </summary> private static void CreateCustomFields() { context.Load(context.EntityTypes.ProjectEntity); context.Load(context.EntityTypes.TaskEntity); context.Load(context.EntityTypes.ResourceEntity); context.ExecuteQuery(); // Create a simple lookup table with 3 values one/two/three csom.LookupTable lookupTB = CreateSimpleLookupTable(); // Create a project custom field with field type TEXT csom.CustomField projCF = context.CustomFields.Add(new csom.CustomFieldCreationInformation() { EntityType = context.EntityTypes.ProjectEntity, FieldType = csom.CustomFieldType.TEXT, Name = projectCFName, LookupTable = null }); // Create a task custom field with field type TEXT, and with the lookup table just created csom.CustomField taskCF = context.CustomFields.Add(new csom.CustomFieldCreationInformation() { EntityType = context.EntityTypes.TaskEntity, FieldType = csom.CustomFieldType.TEXT, Name = taskCFName, LookupTable = lookupTB }); // Create a resource custom field with field type TEXT csom.CustomField resourceCF = context.CustomFields.Add(new csom.CustomFieldCreationInformation() { EntityType = context.EntityTypes.ResourceEntity, FieldType = csom.CustomFieldType.TEXT, Name = resourceCFName, }); context.CustomFields.Update(); context.ExecuteQuery(); }