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 update "statuscode" and "statecode" using web API and JavaScript in MS Dynamics CRM?

(0) ShareShare
ReportReport
Posted on by

Hi,

I want to update 'statuscode' & 'statecode' of accounts.

Can anybody suggest me?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     there is a sample javascript function in this thread (ReactivateCase):

    community.dynamics.com/.../250502

  • Suggested answer
    Jeevarajan Kumar Profile Picture
    781 Most Valuable Professional on at

    Hi Patel,

    Below is the sample code to deactivate accounts. Similarly, you can use different statecode and statuscode based on your business needs.

    For accounts:

    State

    Status Reason

    0 : Active

    1 : Active

    1 : Inactive

    2 : Inactive

    var entity = {};
    entity.statuscode = 2;
    entity.statecode = 1;
    
    var req = new XMLHttpRequest();
    req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/accounts(0000000-0000-0000-0000-000000000000)", 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) {
                
            }
            else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));


    Hope it helps!

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