[英]Javascript - Dynamics CRM Online - Passing a lookup field value to a form through openEntityForm
I am using Xrm.Utility.openEntityForm
to clone a record. 我正在使用Xrm.Utility.openEntityForm
克隆记录。 I have a group of attributes I need to copy over to the new form when I call openEntityForm
. 调用openEntityForm
时,我需要复制一组属性到新表单。 You do this by passing in a parameters
object that is filled with the values of the attributes on the original form. 为此,您可以传入一个parameters
对象,该对象将填充原始表单中的属性值。
My question is: How do I pass the value of a lookup field as a parameter in the parameters object? 我的问题是:如何在参数对象中将查找字段的值作为参数传递? I have a lookup field named "Department" -- I get the original value like this: 我有一个名为“部门”的查找字段-我得到的原始值是这样的:
var department = parent.Xrm.Page.getAttribute("new_departmentid").getValue();
To set the value of the field on the cloned record, I initially create a parameter object -- var parameters = {};
为了在克隆的记录上设置字段的值,我最初创建了一个参数对象var parameters = {};
-- and I set the value for the lookup field like this -- -然后像这样设置查找字段的值-
parameters["new_departmentid"] = department[0].id;
The parameters object gets passed to the openEntityForm method. 参数对象将传递给openEntityForm方法。 This works to set the value of the new form's Department field, BUT the field reads "(No Name)". 这可以设置新表单的“部门”字段的值,但该字段显示为“(无名称)”。
I tried to do something like this: 我试图做这样的事情:
parameters["new_departmentid"] = { id: department[0].id, name: department[0].name, entityType: "new_department" };
But that did not work, and I got errors saying parameter["new_departmentid"]
expects a data type of "UniqueId". 但这是行不通的,并且我收到错误消息,指出parameter["new_departmentid"]
期望数据类型为“ UniqueId”。
How do I pull along the name to correctly populate the lookup field using this method? 如何使用该方法使用名称正确填充查找字段? Thanks for any help. 谢谢你的帮助。
I have a clone function that doesn't use openEntityForm, it just constructs a URL and then calls window.open. 我有一个不使用openEntityForm的克隆函数,它只是构造一个URL,然后调用window.open。 But it should be the same. 但这应该是相同的。 You can pass lookup values by creating three separate parameters: 您可以通过创建三个单独的参数来传递查找值:
This should work for you: 这应该为您工作:
parameters["new_departmentid"] = department[0].id;
parameters["new_departmentidname"] = department[0].name;
parameters["new_departmentidtype"] = department[0].entityType;
Bonus : Note that for lookups that can only take one entity type, you can omit the type parameter. 奖励 :请注意,对于只能采用一种实体类型的查找,可以省略type参数。 It's only needed when passing values to lookups like Owner or Customer which can take multiple types. 仅在将值传递给可以采用多种类型的查询(如所有者或客户)时才需要使用它。 Omitting the parameter will allow you to pass more valuable information before hitting the URL limit of ~2k characters. 省略该参数将使您可以传递更多有价值的信息,然后再达到约2k个字符的URL限制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.