Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Setting Option Set to Unassigned Value through Odata integration API v9.1

Posted on by Microsoft Employee

I'm attempting to update accounts in Dynamics 365 CRM using Odata with API v9.1. 

I can create an account, update the account for all values except when I need to clear a value to NULL when it was already set to a value. 

What should be passed to reset a value to NULL?

This is for Option Set Values when they require BOOLEAN (Numbers) and also String Values.

I attempted to pass the value 'NULL' but for Option Sets I get an error suggesting it requires a BOOLEAN value  and for Sting Values I just populate the field with the word 'NULL'.

Any ideas on what is expected to be passed here?

Thanks,

Alan

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Setting Option Set to Unassigned Value through Odata integration API v9.1

    HI,

    Use below code to set null value to optionset field. I tried this on Lead entity for Lead source field and it is working. Same code can be used in Xrm.wepapi.

    var entity = {};
    entity.leadsourcecode = null;
    
    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl()   "/api/data/v9.1/leads(ec4ba8dc-2cef-e911-a812-000d3a0a827e)", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204) {
                //Success - No Return Data - Do Something
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));

    see below for Xrm.Webapi code

    var entity = {};
    entity.leadsourcecode = null;
    
    Xrm.WebApi.online.updateRecord("lead", "ec4ba8dc-2cef-e911-a812-000d3a0a827e", entity).then(
        function success(result) {
            var updatedEntityId = result.id;
        },
        function(error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );

    If found helpful, Please mark my answer verified.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Setting Option Set to Unassigned Value through Odata integration API v9.1

    Alan,

    Can you please provide the code you used?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans