I am trying to filter a lookup field products with another lookup field editorial (my company sells textbooks).
I know how to retrieve values from the lookup object but I do not know how to pass them into my fetchXml query statement.
function preFilterLookup()
{
Xrm.Page.getControl("new_editorialsearch").addPreSearch(function () {
var ediObject = Xrm.Page.getAttribute("new_editorialsearch").getValue();
// Get the lookup Object, and extract the Value (ID and Text)
if(ediObject != null)
{
var ediTextValue = ediObject[0].name;
var ediID = ediObject[0].id;
// Filter products by editorial
fetchXml = "<filter type='and'><condition attribute='name' operator='eq' value='" + ediTextValue + "' /></filter>";
// Apply the filter to the field
Xrm.Page.getControl("new_engpro").addCustomFilter(fetchXml);
}
});
}
I know I'm doing something wrong because CRM keeps telling me my function is undefined, and I can't see any syntax errors.
Can somebody please tell me the proper way to pass the object name and id into the fetchXml statement?
addCustomFiltercan only be called from theaddPreSearchevent of the same control. So instead of callingaddPreSearchonnew_editorialsearch, call it onnew_engpro.