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)

Update a record using web api.

(1) ShareShare
ReportReport
Posted on by 6

Hello All Experts,

I need to update a single field of a custom entity record based on a click of a custom button.

this will update the field and based on that i want to run a plugin on updation of this particular field.

My approach.

1. Create an Update stage Plugin for the custom entity and filtering attribute to custom single field.

2. Create a custom button on the form using ribbon workbench.

3. Write a javascript function using web api to update the single field  but How To?

can anyone help me in resolving this by using web api??

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    You could use the code below.

    function updateOperationUsingWebAPI() {
    var clientUrl = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest();
    req.open("PATCH", encodeURI(clientUrl + "/api/data/v8.0/accounts(CE49991C-C3B5-E511-80DE-6C3BE5A8AD10)"), true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    var body = JSON.stringify({
    "name": "Updated Sample Account ",
    });
    req.send(body);
    }

    For more details, see https://community.dynamics.com/crm/b/scaleablesolutionsblog/archive/2016/01/18/crud-operations-using-web-api

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi nithya i have an doubt is it necessary to use webapi to update single field cant we do with JS  

  • Suggested answer
    Community Member Profile Picture
    on at

    Thinking aloud.. why not change the attribute value and trigger form save?

    Anyway, there are some WebAPI library you can use to update the record, you don't need to create the entire request and send it everytime.

    Refer to: sdkwebapi.codeplex.com/documentation

  • Community Member Profile Picture
    on at

    hai,

    i have parent record with child records associated with it,whenever i update parent record i want all the child records to be updated.how can i achieve this by using webAPI

  • Suggested answer
    Community Member Profile Picture
    on at
  • Suggested answer
    Pradip Raj Profile Picture
    327 on at

    Hello,

    We can use the below code to update single field value of an entity.

    function updateRecord() {

       var data = {

           "value": "fieldNewValue"

       };

       var req = new XMLHttpRequest();

       req.open("PUT", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/EntitySchemaName(RecordID)/fieldname", true); //Use Plural name of an entity, record id and fieldname

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

       req.setRequestHeader("OData-MaxVersion", "4.0");

       req.setRequestHeader("OData-Version", "4.0");

       req.onreadystatechange = function () {

           if (this.readyState === 4) {

               req.onreadystatechange = null;

               if (this.status === 204) {

                   Xrm.Utility.alertDialog('Record Updated Successfully.');

               } else {

                   //Xrm.Utility.alertDialog(this.statusText); //Use to know status

                   var error = JSON.parse(this.response).error; // Use to throw an error

                   alert(error.message);

               }

           }

       };

       req.send(JSON.stringify(data));

    }

    Refer this link for more details : www.c-sharpcorner.com/.../writing-update-request-using-web-api

    Thanks

    Pradip

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