How to change the Activity Status value using JavaScript in MS Dynamics 365

Change the Activity Status (StateCode) value using JavaScript in Microsoft Dynamics 365 / PowerApps


There are so many questions in Microsoft community forum regarding to Change the Status using JavaScript but none of them have explained it completely. If any beginners wants to use JavaScript to change the Status value in the Activity then they will not be able to do it in right way.


Also Read - How to create a clone record in MS Dynamics 365 using JavaScript
Also Visit - Online Taiyari - Best Online Preparation and Mock Test for Government Exams


I am going to explain you the easy way to change the Status value in the Entity using JavaScript. Believe me you will not need to add any JavaScript  library or any other XrmSvcToolkit. In some articles I saw they have mentioned that you will need to make request to the SOAP API to change the state value. So here I am going to explain you why we will not need anything mentioned above.


Also Read - How to get and set Lookup field in MS Dynamics 365 using JavaScript


There are so many ways to change the Status value like you can use Workflows, Microsoft flow or Plugins. I had a requirement to save the record and change the Status field value and clone the record. So I just wrote a JS function and called that using custom button, everything is working like charm.


Also Read - How to connect Microsoft SharePoint Online using PHP


To change the Status field value you will need to save the current record and then you will be able to change the Value. So here is the JavaScript function which I am using to change the Status (Activity Status) value. I have add this code into my Phone Call entity form.


Also Read - How to connect Quickbooks Online using Microsoft Flow Connector



Here is the Code - 

function updateStatus() { 
Xrm.Page.data.save().then(saveAndUpdate, function () { });
}

function saveAndUpdate(){
Xrm.Page.data.entity.attributes.get("statecode").setValue(1); 
Xrm.Page.data.save();

}





If you guys have any other best way to do it then please let me know in the comment box.


Also Visit - Online Taiyari - Best Online Preparation and Mock Test for Government Exams


If you find this blog post helpful then Please share it with your friends on Social media. Thank you.

Comments