// Load all custom enterprise resource fields and package in an easy to access dictionary. private void LoadCustomFields() { if (AllCustomFields == null) { Console.WriteLine("Loading custom fields and lookup entries..."); // In this example I am only using one custom field. You can add more custom field guids to this list to handle multiple fields var customFields = new List <CustomField> { context.CustomFields.GetByGuid(new Guid(CustomFieldGuid)) }; foreach (var field in customFields) { context.Load(field); context.Load(field.LookupEntries); } context.ExecuteQuery(); // Package custom fields in an easy to access format AllCustomFields = new Dictionary <string, CustomFieldEntity>(); foreach (var field in customFields) { //Console.WriteLine(field.InternalName + " = " + field.Name); var cfe = new CustomFieldEntity() { Id = field.Id.ToString(), InternalName = field.InternalName, Name = field.Name }; foreach (var entry in field.LookupEntries) { //Console.WriteLine("\t" + entry.InternalName + " = " + entry.FullValue); cfe.LookupEntries.Add( entry.FullValue.ToLower(), new LookupEntryEntity() { Id = entry.Id.ToString(), InternalName = entry.InternalName, Value = entry.FullValue } ); } AllCustomFields.Add(field.Id.ToString(), cfe); } } }
// Load all custom enterprise resource fields and package in an easy to access dictionary. private void LoadCustomFields() { if (AllCustomFields == null) { Console.WriteLine("Loading custom fields and lookup entries..."); // In this example I am only using one custom field. You can add more custom field guids to this list to handle multiple fields var customFields = new List<CustomField> { context.CustomFields.GetByGuid(new Guid(CustomFieldGuid)) }; foreach (var field in customFields) { context.Load(field); context.Load(field.LookupEntries); } context.ExecuteQuery(); // Package custom fields in an easy to access format AllCustomFields = new Dictionary<string, CustomFieldEntity>(); foreach (var field in customFields) { //Console.WriteLine(field.InternalName + " = " + field.Name); var cfe = new CustomFieldEntity() { Id = field.Id.ToString(), InternalName = field.InternalName, Name = field.Name }; foreach (var entry in field.LookupEntries) { //Console.WriteLine("\t" + entry.InternalName + " = " + entry.FullValue); cfe.LookupEntries.Add( entry.FullValue.ToLower(), new LookupEntryEntity() { Id = entry.Id.ToString(), InternalName = entry.InternalName, Value = entry.FullValue } ); } AllCustomFields.Add(field.Id.ToString(), cfe); } } }