Hi, I’m filtering a lookup field called DocTypeLookup, using the following code, based on a string:
// filter controls for the document type
function filterLookup(v){
// setting filtration
fd.field('DocTypeLookup').filter = "Category eq '" + v + "'";
**fd.field('DocTypeLookup').widget.dataSource.read();**
}
//filter lookup when form opens
filterLookup('Feasibility');
I seem to get an error on the .widget.dataSource.read(), however this I think is new behaviour, as I don’t think I previously got this error - ‘TypeError: Cannot read property ‘dataSource’ of null’ There is definitely a category called Feasibility on the lookup list, and the lookup field works in the form, filtering down the options.
Regardless of whether I leave this line in, or comment the line out, the filter works on the drop down. Any idea why this is happening?
You need to use the on ready for the lookup, the chances are the function is running before the lookup is fully loaded.
Try This
// filter controls for the document type
function filterLookup(){
// setting filtration
var v = 'Feasibility'
fd.field('DocTypeLookup').filter = "Category eq '" + v + "'";
fd.field('DocTypeLookup').widget.dataSource.read();
}
//filter lookup when form opens
fd.field('DocTypeLookup').ready().then(filterLookup);