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:

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);
    }
);

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:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

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 *