简体   繁体   English

如何使用JavaScript清除MS Dynamics CRM 4.0中的“查找”字段

[英]How to clear Lookup field in MS Dynamics CRM 4.0 using JavaScript

I'm trying clear the value of a lookup field via Javascript. 我正在尝试通过Javascript清除查找字段的值。 I've tried this: 我试过这个:

crmForm.all.new_mylookupfield.DataValue = null;

But that isn't working. 但这不起作用。 I inspected the DataValue of the lookup when it was in fact cleared and it returned a null. 我检查了查找的DataValue,当它实际上被清除并返回null。

alert(document.getElementById("new_mylookupfield").DataValue == null); // true

I'm must be missing something here.... 我必须在这里遗漏一些东西....

Thanks for the help! 谢谢您的帮助!

UPDATE: I finally got around to testing some of the suggestions. 更新:我终于开始测试一些建议了。 I'm not sure what I was doing wrong initially, but both of these methods work to clear a lookup via JavaScript: 我不确定我最初做错了什么,但这两种方法都可以通过JavaScript清除查找:

crmForm.all.new_mylookupfield.DataValue = null;
crmForm.all.new_mylookupfield.DataValue = [];

Lookup controls have a specific type of object for their DataValue. 查找控件的DataValue具有特定类型的对象。 It's an array of objects that look like this: 它是一个对象数组,如下所示:

{
    id: /* item id */,
    typename: /* entity type name */,
    name: /* text to display in link */
}

If you want to remove all values from the lookup, you can set it to null, but it's better to just set it to an empty array. 如果要从查找中删除所有值, 可以将其设置为null,但最好将其设置为空数组。

If you assign the value, but it doesn't seem to change anything, then you are probably not typing the correct id for the attribute. 如果您指定了值,但似乎没有更改任何内容,那么您可能没有为该属性键入正确的ID。 For example: If I have an entity with a lookup attribute of sneakers_brokerid , then I need to assign that value like so: 例如:如果我有一个查找属性为sneakers_brokerid的实体,那么我需要像这样分配该值:

 crmForm.all.sneakers_brokerid.DataValue = [];

我不记得必须这样做,但你尝试将值设置为一个长度为零的新Array()吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态 crm 4.0 查找字段 onload() 查询 - dynamics crm 4.0 lookup field onload() query 使用Dynamics CRM 4.0中的JavaScript计算年龄 - Calculate the Age using javascript in Dynamics CRM 4.0 禁用选项列表字段功能会重置值 Dynamics crm 4.0 Javascript - Disabling picklist field function resets value Dynamics crm 4.0 Javascript 如何在Microsoft dynamics crm 365中通过javascript获取查找字段的值 - How can I get the value of a lookup field by javascript in Microsoft dynamics crm 365 MS Dynamics CRM 4.0-onChange事件错误 - MS Dynamics CRM 4.0 - onChange event error Javascript / MS Dynamics CRM 2016:使用确认框更改选项集字段的值 - Javascript / MS Dynamics CRM 2016: Changing value of option set field using confirm box 如何序列化 jQuery CRM 动态门户中的查找字段 - How to serialize lookup field in jQuery CRM Dynamics Portal 如何在 Dynamics CRM 4.0 中传递 Javascript 中的 Null 值? - How to pass the Null Value in Javascript in Dynamics CRM 4.0? 使用 Javascript 访问 MS CRM 4.0 中 IFrame 中加载的页面上的控件 - Accessing Controls on page loaded in IFrame in MS CRM 4.0 using Javascript Dynamics Crm - 在 Javascript 中获取快速创建表单加载时的触发查找字段? - Dynamics Crm - Get Triggering lookup field on quick create form load in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM