Announcements
Hello,
I found in MS docs how to create with c# a Multiselect option set as shown in the code below :
int _languageCode = 1033; //English MultiSelectPicklistAttributeMetadata outDoorActivitiesAttribute = new MultiSelectPicklistAttributeMetadata() { SchemaName = "sample_OutdoorActivities", LogicalName = "sample_outdooractivities", DisplayName = new Label("Outdoor activities", _languageCode), RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None), Description = new Label("Outdoor activities that the contact likes.", _languageCode), OptionSet = new OptionSetMetadata() { IsGlobal = false, OptionSetType = OptionSetType.Picklist, Options = { new OptionMetadata(new Label("Swimming",_languageCode),1), new OptionMetadata(new Label("Hiking",_languageCode),2), new OptionMetadata(new Label("Mountain Climbing",_languageCode),3), new OptionMetadata(new Label("Fishing",_languageCode),4), new OptionMetadata(new Label("Hunting",_languageCode),5), new OptionMetadata(new Label("Running",_languageCode),6), new OptionMetadata(new Label("Boating",_languageCode),7), new OptionMetadata(new Label("Skiing",_languageCode),8), new OptionMetadata(new Label("Camping",_languageCode),9)} } }; CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest { EntityName = Contact.EntityLogicalName, Attribute = outDoorActivitiesAttribute };
But my need is how to add a new OptionMetadata with a new label and new value to an existant Multiselect option set ?
Thanks Mehdi you are the best
Hi Mehdi,
Yes you are right it work for both insertOptionValueRequest and updateOptionValueRequest.
It worked in my environment for the multiselect option set.
Hi Mehdi,
Thank you for your quick answer, but i believe it will work just for an optionset not for a multiselect optionset.
Hi,
Please refer to the code below snippet from MS Docs:
Local option:
// Create a request. InsertOptionValueRequest insertOptionValueRequest = new InsertOptionValueRequest { AttributeLogicalName = "new_picklist", EntityLogicalName = Contact.EntityLogicalName, Label = new Label("New Picklist Label", _languageCode) }; // Execute the request. int insertOptionValue = ((InsertOptionValueResponse)svc.Execute( insertOptionValueRequest)).NewOptionValue; Console.WriteLine("Created {0} with the value of {1}.", insertOptionValueRequest.Label.LocalizedLabels[0].Label, insertOptionValue);
Global option:
// Use InsertOptionValueRequest to insert a new option into a // global option set. InsertOptionValueRequest insertOptionValueRequest = new InsertOptionValueRequest { OptionSetName = _globalOptionSetName, Label = new Label("New Picklist Label", _languageCode) }; // Execute the request and store the newly inserted option value // for cleanup, used in the later part of this sample. _insertedOptionValue = ((InsertOptionValueResponse)svc.Execute( insertOptionValueRequest)).NewOptionValue; //Publish the OptionSet PublishXmlRequest pxReq2 = new PublishXmlRequest { ParameterXml = String.Format("{0}", _globalOptionSetName) }; svc.Execute(pxReq2);
Based on the documentation, this will work for the option set. However, it also works for Multiselect option set too. (tested with global)
https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.messages.insertoptionvaluerequest?view=dynamics-general-ce-9
André Arnaud de Cal...
294,000
Super User 2025 Season 1
Martin Dráb
232,850
Most Valuable Professional
nmaenpaa
101,158
Moderator