Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

How to programmatically insert/update/delete an option from optionset (server side)?

(0) ShareShare
ReportReport
Posted on by

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

  • Suggested answer
    Haansi Profile Picture
    Haansi 1,431 on at
    RE: How to programmatically insert/update/delete an option from optionset (server side)?

    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.

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: How to programmatically insert/update/delete an option from optionset (server side)?

    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;

    CQ24.PNG

    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/.../

    Please mark my answer verified if i were helpful

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans