web
You’re offline. This is a read only version of the page.
close
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,119 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

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans