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

荒凉一梦 提交于 2020-01-03 17:16:10

问题


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?


回答1:


To use the new (CRM 365) methods you need to do two things:

When you write your form library, your function must include a parameter. This is set by CRM when it calls your function. In my example here, the parameter name is executionContext but the name does't matter

Once you have this CRM parameter, you can get the Form Context which is the new Xrm.Page equivalent. See below

function onLoad(executionContext)
{
  var formContext = executionContext.getFormContext();

  var lookup = formContext.getAttribute("new_account").getValue();
  formContext.getAttribute("new_name").setValue("Your Account Name is:" + lookup[0].name);
}

Secondly, when you register your form library, you must pass the Execution Context. This is what tells CRM that your form library method has the executionContext parameter that must be set




回答2:


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.



来源:https://stackoverflow.com/questions/52677158/how-can-i-get-the-value-of-a-lookup-field-by-javascript-in-microsoft-dynamics-cr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!