Update a Record using Xrm.WebApi

1 Comment

Let’s look at how we can use the Xrm.WebApi to update a record.

Let’s use the Account entity, where we have a field called My New Field (new_mynewfield):

Here’s the update script:

[sourcecode language=”CSharp”] var data =
{
"new_mynewfield": "TEST"
}

var Id = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");

Xrm.WebApi.updateRecord("account", Id, data).then(
function success(result) {
console.log("Success");
},
function (error) {
console.log(error.message);
}
);
[/sourcecode]

We can run this in the browser console or in a web resource. We see we get a Success callback:

In advanced find, we see the field has been updated:

Interestingly, if we were to run this with the Account record open, as the update is being done in the background, the form does not show as being dirty (i.e. unsaved changes):

On reselecting the form, we see the field updated:

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

One Response to Update a Record using Xrm.WebApi

  1. Hi Without refreshing the screen I am not able to see the updated value in the screen. Please provide me a solution how to update the fields and show record without refreshing the page.

Leave a Reply

Your email address will not be published. Required fields are marked *