admin管理员组

文章数量:1302374

I'm trying clear the value of a lookup field via 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.

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:

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

I'm trying clear the value of a lookup field via 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.

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:

crmForm.all.new_mylookupfield.DataValue = null;
crmForm.all.new_mylookupfield.DataValue = [];
Share Improve this question edited Aug 17, 2010 at 4:49 Greg McGuffey asked May 27, 2010 at 18:40 Greg McGuffeyGreg McGuffey 3,3163 gold badges40 silver badges61 bronze badges 1
  • Did you try crmForm.all.new_mylookupfield.DataValue = ""; If you put crmForm.all.new_mylookupfield.DataValue = "HELLO"; what does it do? – xt_20 Commented May 28, 2010 at 1:36
Add a ment  | 

2 Answers 2

Reset to default 5

Lookup controls have a specific type of object for their 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.

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. For example: If I have an entity with a lookup attribute of sneakers_brokerid, then I need to assign that value like so:

 crmForm.all.sneakers_brokerid.DataValue = [];

I don't remember having to do this, but have you tried setting the value to just a new Array() with length zero?

本文标签: How to clear Lookup field in MS Dynamics CRM 40 using JavaScriptStack Overflow