Skip to main content
Microsoft Dynamics CRM forum
Answered

Javascript in dynamics crm

editSubscribe (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
Attachments
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li 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
     

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,080 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,601 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans