Announcements
No record found.
Hello Friends,
I am facing a new issue that i am unable to add custom filter to the lookup field.
Because the addSearchFilter() is not working on the Model Driven Apps.
Here is the code that i'm using
// JavaScript source codefunction preFilterLookup() { debugger; try { if (Xrm.Page.getControl("crda6_product") != null && Xrm.Page.getControl("crda6_product") != undefined) { Xrm.Page.getControl("crda6_product").addPreSearch(addCustomeLookupFilter); } } catch (e) { throw new Error(e.Message); }}function addCustomeLookupFilter() { var functionName = "addCustomeLookupFilter"; try { var formvalue = Xrm.Page.getAttribute("crda6_origin").getValue(); if (formvalue != null && formvalue != undefined) { fetchXml = " <filter type='and'><condition attribute='crda6_origin' operator='like' value='%import%' /></filter>"; Xrm.Page.getControl("crda6_product").addCustomFilter(fetchXml); } } catch (e) { throw new Error(e.Message); }}
If anyone has any information on this issue please let know that would be very helpful.
Regards
Shashikant Saxena
Are you getting any errors?
Your .addCustomFilter is missing the 2nd parameter - entity type docs.microsoft.com/.../addcustomfilter
We have a PreFilter working in the UCI, but we did find an issue that the Lookup would show errors when someone tried to type or lookup existing values if the results (after the prefilter was applied) contained the name field empty/null.
Hi,
Are you getting any error message?
Hi parnter,
I also tried your code first and it gave me an error message without any information.
Then I removed the "addCustomeLookupFilter" function and add a function in "addPreSearch()" directly and then it worked well!
You could also refer to the following post.
https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/294498/addpresearch-not-working-in-dynamics-crm-365-9-0
BTW, UCI will not support "Xrm.page" in the future and I suggest that you could use "executionContext" instead.
Hope it helps.
Best Regards,
Leo
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
Congratulations to our community stars!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Daniyal Khaleel 60 Most Valuable Professional
11manish 23 Super User 2026 Season 2
Travis South 10