Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to set null in a option set attribute with the help of web API

(0) ShareShare
ReportReport
Posted on by 12,085 Moderator

Hi All,

I am using below code to update an entity.

function UpdateOrphan(_formContext) {
    var entityUpdate = {};
    var newAcademicLevel = GetNewAcademicLevel(_formContext),
        oldAcademicLevel = GetOldAcademicLevel(_formContext);
    if (newAcademicLevel) {
        entityUpdate[orphanFields.CurrentAcademicLevel] = newAcademicLevel;
    } else if (oldAcademicLevel) {
        entityUpdate[orphanFields.CurrentAcademicLevel] = null;
    }
    var orphan = GetOrphan(_formContext);
    UpdateAndReturnUpdateStatus(entityUpdate, orphan[0].id, globalVariables.WebAPIVersion, entitys.Orphans);
}

function UpdateAndReturnUpdateStatus(entity, recordID, webAPIVersion, entitysPluralName) {
    recordID = recordID.replace(/[{}]/g, "");

    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/" + webAPIVersion + "/" + entitysPluralName + "(" + recordID + ")", false);//Sync
    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) {
                globalVariables.UpdateStatus = true;
            }
            else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));
}

I am not able to set null with this code. I am receiving 204 in the return.

What is wrong in my code?

Thanks

Regards,

AW

*This post is locked for comments

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to set null in a option set attribute with the help of web API

    Hello,

    I would recommend to use fiddler to check what request is sent to server and provide correspond schreenshot here.

    I'm suspicious that your code doesn't set field to null value or something on the backend sets field back - plugin or workflow.

    PS FYI 204 ststus is absolutely normal response - it means that there was no data returned as a response.

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans