[英]Lookup field formatted value from Web API in Microsoft Dynamics CRM is undefined (cannot get formatted value)
[英]How can I get the value of a lookup field by javascript in Microsoft dynamics crm 365
我试图获取一个查找字段值,并通过Microsoft Dynamics CRM中的Javascript将值设置为另一个字段(例如“名称”字段)。 我该怎么做?
我在docs.microsoft上找到了它。 要做到这一点,首先您应该了解Dynamics CRM中的文档对象模型,称为“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);
您可以将其用作函数,并在Microsoft动态CRM表单的save(OnSave)事件上调用它。
要使用新的(CRM 365)方法,您需要做两件事:
编写表单库时,函数必须包含参数。 这是由CRM在调用您的函数时设置的。 在我的示例中,参数名称是executionContext
但名称无关紧要
获得此CRM参数后,您可以获得表单上下文 ,它是新的Xrm.Page
等效项。 见下文
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);
}
其次,当您注册表单库时,必须传递执行上下文。 这告诉CRM您的表单库方法具有必须设置的executionContext
参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.