Announcements
Hello Folks,
I am trying to write a program to programmatically insert/update/delete an option in OptionSet in an entity. I came across some documentation on doing it with global optionsets but couldn't find much help with local option sets. Also, I want to do it in a batch instead of doing it one by one passing the request to organization service.
Appreciate some ideas here.
Thanks,
For doing operations on optionset we have different message request classes. Please see this link:
docs.microsoft.com/.../metadata-option-sets
Same classes will work for global or local option sets. For local you will need to use approperate properties. Please see attributelogical name and entity name properties.
Hello,
You could modify the sample for globalto make it work for local optionset.
Please see code below to add option in local optionset.
// Use InsertOptionValueRequest to insert a new option into a // Local option set. InsertOptionValueRequest insertOptionValueRequest = new InsertOptionValueRequest { AttributeLogicalName = "accountcategorycode", Label = new Label("My Category Code", 1033), Value = 3, EntityLogicalName ="account" }; // Execute the request and store the newly inserted option value // for cleanup, used in the later part of this sample. var _insertedOptionValue = ((InsertOptionValueResponse)crmSvc.Execute( insertOptionValueRequest)).NewOptionValue;
Lanuage code - https://www.crmportalconnector.com/developer-network/documentation/developing-for-tpc/language-code-table
Microsoft DOC Sample code - https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/org-service/metadata-global-option-set-options
Use executemultiplerequest to create option in batch - https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/org-service/use-executemultiple-improve-performance-bulk-data-load
Make sure you publish your changes either from UI or from Code - xrmdynamicscrm.wordpress.com/.../
André Arnaud de Cal...
294,261
Super User 2025 Season 1
Martin Dráb
232,994
Most Valuable Professional
nmaenpaa
101,158
Moderator