web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Automatically updating a field

(0) ShareShare
ReportReport
Posted on by 20

I have the phone call form and I would like to get the Account Name and phone number to automatically populate based on the contact name.

Do you know how I can build this to pull through this information?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi Victoria,

    You can do this using webapi and client side scripting.

    You would get the id of the contact using script:

    var contactId = Xrm.Page.getAttribute("contactid").getValue();

    You would then call the following api passing the contact id to it;

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts(" + contactId + ")?$select=_accountid_value&$expand=parentcustomerid_account($select=name,telephone1)", true);

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

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

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

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

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var result = JSON.parse(this.response);

               var _accountid_value = result["_accountid_value"];

               var _accountid_value_formatted = result["_accountid_value@OData.Community.Display.V1.FormattedValue"];

               var _accountid_value_lookuplogicalname = result["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];

               if (result.hasOwnProperty("parentcustomerid_account")) {

                   // These are the name and phone fields.

                   var parentcustomerid_account_name = result["parentcustomerid_account"]["name"];

                   var parentcustomerid_account_telephone1 = result["parentcustomerid_account"]["telephone1"];

                   // Use setValue to populate the fields.

                   var contactId = Xrm.Page.getAttribute("telephone1").setValue(parentcustomerid_account_telephone1);

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    Hope this helps.

  • Victoria Winn Profile Picture
    20 on at

    Hi Vicky

    I followed all the steps you outlined but for whatever reason after saving ad closing and publishing all customisations - it doesn't update.

    Attached are the screen shots to show what I did as I followed your steps exactly as you set them out.

    Do you have any further ideas?

    Thank you

    Vicky

    Step2.jpgStep2.jpg

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans