Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

InsertOptionValueRequest works on local dev machine but fails on server

(0) ShareShare
ReportReport
Posted on by 40

I have written some code that programmatically creates a new optionset value in a multiselect optionset.

The code works fine when executing on my local machine (which points to Dynamics 365 development server).

This code will run in a plugin and when I upload the plugin to the development server and perform the action that triggers the code then the code fails with a null reference exception on this line:

var resp = (InsertOptionValueResponse)_service.Execute(insertOptionValueRequest);

I can't figure out why, if anyone has any input it would be much appreciated.

InsertOptionValueRequest insertOptionValueRequest =
                        new InsertOptionValueRequest
                        {
                            AttributeLogicalName = "releye_salesexcellenceassessmentforms2",
                            EntityLogicalName = Lead.EntityLogicalName,
                            Label = new Label(text, 1033),
                        };

                    var resp = (InsertOptionValueResponse)_service.Execute(insertOptionValueRequest);

  • Suggested answer
    Fedorov Profile Picture
    40 on at
    RE: InsertOptionValueRequest works on local dev machine but fails on server

    I just got it to work. The code was actually executed in the CustomApi context.

    But when I moved the function to instead execute on the update (async) of another field where we store the text (dont ask why..) then it works fine...

    Values will be created very rarely and the customer really wanted it to work this way....

  • Verified answer
    Guido Preite Profile Picture
    54,077 Moderator on at
    RE: InsertOptionValueRequest works on local dev machine but fails on server

    depends on how the plugin is registered. If is registered as running in the user context (the default) the user needs to have the right permissions (like System Administrator or System Customizer) in order to add an option.

    However I strongly advise against creating optionset values on the fly, they are not made for this scenario, is better to create a custom table and a lookup if the user needs to create values.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,017 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans