Search code examples
javascriptdynamics-crm

How can I get the value of a lookup field by javascript in Microsoft dynamics crm 365


I am trying to get a lookup field value and set the value into another field ('Name' field for example) by Javascript in Microsoft Dynamics CRM. How can I do it?


Solution

  • I found it on docs.microsoft. To do this, first you should know about Document Object Model in Dynamics CRM which is called "Xrm":

    var lookupValue=Xrm.Page.data.entity.attributes.get('new_account').getValue()[0].name;
    Xrm.Page.getAttribute("new_name").setValue("Your Account Name is:"+lookupValue);
    

    You can use it as a function and call it on save (OnSave) event of Microsoft dynamics CRM Form.