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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Use CRM REST Builder to update fields of contact ( lookup ) on account.

(0) ShareShare
ReportReport
Posted on by 65
I'm new to dynamics 365 and I've been trying to use CRM REST Builder generated code to use in Dynamics to update fields of contact(lookup) on account . My question is how do I use REST Builder to update any 2 fields on contact (lookup) in account ?
Thanks in advance.
I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Shubham,

    The OOB relationship between Account and Contact is 1:N, so it should that one Account lookup field in the Contact form.

    pastedimage1603426313587v1.png

    As mentioned above, you want to update fields of contact entity in the Account form, Right?

    The account is parent record and contact is child record, one parent record may have many child records.

    So what you need is that update child records when parent record is triggered.

    1.Reterieve Contacts based on current Account id.

     pastedimage1603426794720v3.png

    2.Update Contact fields based on contact id that from step1.

    pastedimage1603426916981v4.png

    3.Replacing the sample id in the screenshot with a dynamic ID in the JS code.

    function updateContact() {
        var id = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');//get current account id
        Xrm.WebApi.online.retrieveMultipleRecords("contact", "?$select=contactid,telephone1&$filter=_accountid_value eq " id "").then(
            function success(results) {
                for (var i = 0; i < results.entities.length; i  ) {
                    var contactid = results.entities[i]["contactid"];
                    var telephone1 = results.entities[i]["telephone1"];
                    
                    //update child contacts fields
                    var entity = {};
                    entity.telephone1 = "test phone update";//use value you need to update fields.
    
                    Xrm.WebApi.online.updateRecord("contact", "" contactid "", entity).then(
                        function success(result) {
                            var updatedEntityId = result.id;
                        },
                        function (error) {
                            Xrm.Utility.alertDialog(error.message);
                        }
                    );
    
                }
            },
            function (error) {
                Xrm.Utility.alertDialog(error.message);
            }
        );
    }

    4.Add the js code to the contact form.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans