Hello Experts,
I am trying to duplicate all fields of an entity into another entity via a C# ConsoleApp.
I am struggling to duplicate an attribute of type Picklist (Option Set in CRM) which has an underlying Global Option Set.
I am getting this Error : "Error: You cannot create a system option set directly through the SDK. Only custom option sets can be created directly through the SDK."
This is the code:
*NOTE: This code works for Attributes of type Picklist (Option Set in CRM) which are NOT Global. It only fails when it encounters an attribute which uses a Global Option Set.
foreach (AttributeMetadata attr in attributes) { /* Will process Attributes which: */ if (attr.IsCustomAttribute != null && attr.IsCustomAttribute.Value == true && /* Are Custom Attributes (Created by User) */ attr.AttributeType.HasValue && attr.AttributeType.Value.ToString() == "Picklist" && /* AND are of Type Option Set */ !logicalNamesToIgnore.Contains(attr.LogicalName)) /* AND are NOT in the IGNORE list */ { EnumAttributeMetadata enumAttr = (EnumAttributeMetadata)attr; CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest { EntityName = ChildEntityLogicalName, Attribute = enumAttr }; service.Execute(createAttributeRequest); Console.WriteLine($"Attribute Created ---> {enumAttr.LogicalName}"); } }
Thanks,
Victor