Skip to main content

Notifications

Announcements

No record found.

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
  • 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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,283 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,025 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans