hi all , I am using crm 2016 and trying to filter lookup based on another field. In this custom form there is a lookup field for Quote and lookup field for service rentals (call new_servicechargeid) I am reading customerid from Quote lookup value. then filter service charge lookup to list service rentals link to quote customer only , here is my code . that does not filter anything though :( any help would be great
function filterServiceCharges() { if (Xrm.Page.getControl("new_relatedquoteid") != null && Xrm.Page.getControl("new_relatedquoteid") != undefined) { Xrm.Page.getControl("new_servicechargeid").addPreSearch(function () { addServiceChargeLookupFilter(); }); } } function addServiceChargeLookupFilter() { var functionName = "addServiceChargeLookupFilter"; try { var quotelookup = Xrm.Page.getAttribute("new_relatedquoteid").getValue(); if (quotelookup != null) { var quoteid = quotelookup[0].id; SDK.REST.retrieveRecord( quoteid, "Quote", "CustomerId", null, function (quote) { var customerlookup = quote.CustomerId; if (customerlookup != null && customerlookup != undefined) { var customerid = customerlookup.Id; if (customerid != null && customerid != '' && customerid != undefined) { fetchXml = "<filter type='and'><condition attribute='us_sc_accountid' operator='eq' value='" + customerid + "'/></filter>"; Xrm.Page.getControl("new_servicechargeid").addCustomFilter(fetchXml); } } }, errorHandler ); } } catch (e) { throw new Error(e.message); } }