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

Announcements

News and Announcements icon
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
    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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 143 Super User 2026 Season 1

#2
Hamza H Profile Picture

Hamza H 142 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 121

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans