web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans