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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Javascript in dynamics crm

(0) ShareShare
ReportReport
Posted on by
How to get account related information when loading the contact form, for example I want to get account related fax value when i enter the account name on contact form  . explain with the code
I have the same question (0)
  • Verified answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Javascript in dynamics crm
    Hi,
     
    I added a Text Area field to the Contact form to display the account's fax.
    The code is as follows.
     
    function onload(executionContext){
      var formContext = executionContext.getFormContext();
     
      //Gets the value of the Account Lookup field.
      var account = formContext.getAttribute("parentcustomerid");
     
       //If the Account Lookup field is empty, exit and clear the Text Area field.
      if(!account){
        formContext.getAttribute("cr8a7_textarea").setValue(null)
        return;
      }
     
      //Get the ID of the account record in the account lookup field
      var accountId = account[0].id;
     
      //Retrieves the value of this account record.
      Xrm.WebApi.retrieveRecord("account", accountId, "?$select=name,fax").then(
        function success(result) {
           
            // Populate the Text Area field with the fax for this account record.
          formContext.getAttribute("cr8a7_textarea").setValue("Retrieved values: Name: " + result.name + ", Fax: " + result.fax)
           
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );
     
    }
     
     
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li
     

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 235

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 177

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 156 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans