I want this functionality to prefilter based on TWO lookups on the form, Im no expert and have tried to cobble together the code from the internet
I have made the fields generic, but in a nutshell, I have two functions - EntitySearch and BaseFilter
The first function hopefully checks that the lookup I wanto to populate is on the form, and if it is prefilter this with what is in the second function
The second function then references two other lookups to two other entities.
It check that the field is present and has a value in it. If it does it then gets the value from the first value in it.
I then hopefully checks to see if both lookups have data, and it does, then it pre-filters the search with the xml.
However I am getting the following error, and the look up is not working.
@xxxxx.crm11.dynamics.com/.../ClientApiWrapper.aspx line 159 > eval:1:1
RunHandlerInternal@xxxxx.crm11.dynamics.com/.../ClientApiWrapper.aspx
RunHandlers@xxxxx.crm11.dynamics.com/.../ClientApiWrapper.aspx
OnScriptTagLoaded@xxxxx.crm11.dynamics.com/.../ClientApiWrapper.aspx
AppendScriptTag/scriptTag.onload/<@xxxxx.crm11.dynamics.com/.../ClientApiWrapper.aspx
Could someone infinity more talented than I please cast an eye over the code to see if I am missing anything.
Ta Lee
function EntitySearch() { if (Xrm.Page.getControl("new_basefield") != null) { Xrm.Page.getControl("new_basefield").addPreSearch(BaseFilter); } } function BaseFilter() { var LookupOne; var LookupOneID = null; var LookupTwo; var LookupTwoID = null; var fetchQuery; try { if (Xrm.Page.getControl("new_lookuponefield") != null && Xrm.Page.getControl("new_lookuponefield").getAttribute().getValue() != null) { LookupOne = Xrm.Page.getControl("new_lookuponefield").getAttribute().getValue(); LookupOneID = LookupOne[0].id; } if (Xrm.Page.getControl("new_lookuptwofield") != null && Xrm.Page.getControl("new_lookuptwofield").getAttribute().getValue() != null) { LookupTwo = Xrm.Page.getControl("new_lookuptwofield").getAttribute().getValue(); LookupTwoID = LookupTwo[0].id; } if (LookupOneID != null || LookupOneID != undefined) && (LookupTwoID != null || LookupTwoID != undefined) { fetchQuery = "<filter type='and'>" + "<condition attribute='statecode' operator='eq' value='0' />" + "<condition attribute='new_lookuponefield' operator='eq' value='" + LookupOneID + "' />" + "<condition attribute='new_lookuptwofield' operator='eq' value='" + LookupTwoID + "' />" + "</filter>"; Xrm.Page.getControl("new_basefield").addCustomFilter(fetchQuery); } } catch (e) { Xrm.Utility.alertDialog("BaseFilter Error: " + (e.description || e.message)); } }