How to clear search field in MS Dynamics CRM 4.0 using JavaScript

I am trying to clear the value of a search field through Javascript. I tried this:

crmForm.all.new_mylookupfield.DataValue = null; 

But that does not work. I checked the DataValue search when it was actually cleared and it returned zero.

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

I have to skip something here.

Thanks for the help!

UPDATE: I finally got to testing some suggestions. I'm not sure what I was doing wrong, but both of these methods work to clear the search through JavaScript:

 crmForm.all.new_mylookupfield.DataValue = null; crmForm.all.new_mylookupfield.DataValue = []; 
+4
source share
2 answers

Lookup controls have a specific object type for a DataValue. This is 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 search, you can set it to null, but it's better to just set it to an empty array.

If you assign a value, but it does not change anything, you most likely will not type the correct identifier for the attribute. For example: if I have an object with the lookup attribute sneakers_brokerid , then I need to assign this value as follows:

  crmForm.all.sneakers_brokerid.DataValue = []; 
+5
source

I don’t remember to do this, but have you tried setting the value only for the new array () with zero length?

+3
source

Source: https://habr.com/ru/post/1311126/


All Articles