In my model-driven app, I need to filter a lookup field in Javascript using complex criteria. I set it up to run a FetchXML query, joining multiple tables. That provides a list of matching IDs. I then loop through those IDs and build the FetchXML filter string with a "value" tag for each ID. I then call addPreSearch and pass in the filter string. My code:
var filterXML = "<filter>" +
"<condition attribute='" + entityName + "id' operator='in' >";
if (result.entities.length > 0) {
for (var i = 0; i < result.entities.length; i++) {
filterXML = filterXML + "<value>" + result.entities[i][entityName + "id"] + "</value>";
}
}
else {
filterXML = filterXML + "<value>00000000-0000-0000-0000-000000000000</value>";
}
filterXML = filterXML + "</condition>" +
"</filter>";
ctrl.addPreSearch(function () {
Spear.Utility.setLookupFilter(formContext, ctrlName, filterXML);
});
This works great until the quantity of matching IDs gets large. I'm not sure what quantity breaks it - I know it breaks with 1200, but probably much less than that. The URI is too long when the lookup takes place.
Any ideas for how to perform advanced filtering of a lookup when there are a lot of matching values?
I could store the IDs in a table temporarily, but how to do a join on that temp table in the FetchXML? It doesn't like when I add a "link-entity" tag.
Thanks,
Todd