简体   繁体   English

Javascript-Dynamics CRM Online-通过openEntityForm将查找字段值传递给表单

[英]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: 您可以通过创建三个单独的参数来传递查找值:

  1. one for the id using the field's id 一个使用字段的ID作为ID
  2. one for the name using the field's id + "name" 一个使用字段的ID +“名称”作为名称
  3. one for the type using the field's id + "type". 一种类型,使用字段的ID +“类型”。

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.

相关问题 如何在Microsoft dynamics crm 365中通过javascript获取查找字段的值 - How can I get the value of a lookup field by javascript in Microsoft dynamics crm 365 如何使用JavaScript清除MS Dynamics CRM 4.0中的“查找”字段 - How to clear Lookup field in MS Dynamics CRM 4.0 using JavaScript 动态 crm 4.0 查找字段 onload() 查询 - dynamics crm 4.0 lookup field onload() query CRM Dynamics,如何使用一种形式传递值,并使用Xrm.Utility.openEntityForm()在新的Entity(form)中设置值; - CRM Dynamics , How to pass values from one form and set the values in a new Entity(form) using Xrm.Utility.openEntityForm(); 禁用选项列表字段功能会重置值 Dynamics crm 4.0 Javascript - Disabling picklist field function resets value Dynamics crm 4.0 Javascript 检索快速查看表单值 - Dynamics CRM JavaScript - Retrieve Quick View Form Value - Dynamics CRM JavaScript Microsoft Dynamics CRM 中来自 Web API 的查找字段格式化值未定义(无法获取格式化值) - Lookup field formatted value from Web API in Microsoft Dynamics CRM is undefined (cannot get formatted value) 如何使用 JavaScript 在 Dynamics 365 CRM 内部部署的表单上填写父查询? - How to use JavaScript to fill parent lookup on form in Dynamics 365 CRM on-premise? 使用javascript从crm 2015中的查找字段获取值 - get a value from lookup field in crm 2015 using javascript 使用JavaScript将参数传递给Dynamics CRM中的IFRAME - Passing parameters to IFRAME in Dynamics CRM using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM