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 = [];
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 = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With