web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

AddSerarchFilter method is not working in the D365 v9 Unified interface(Model Driven App)

(0) ShareShare
ReportReport
Posted on by 20

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 code
function 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

  • Suggested answer
    Fubar Profile Picture
    2,761 on at

    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.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Are you getting any error message?

  • Suggested answer
    LeoAlt Profile Picture
    16,341 Moderator on at

    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!

    function preFilterLookup(executionContext) {

        var formContext = executionContext.getFormContext();
        try {
            if (formContext.getControl("ownerid") != null && formContext.getControl("ownerid") != undefined) {
                fetchXml = " <filter type='and'><condition attribute='domainname' operator='like' value='%admin%' /></filter>";
                formContext.getControl("ownerid").addPreSearch(function () {
    formContext.getControl("ownerid").addCustomFilter(fetchXml);
    });
            }
        } catch (e) {
            throw new Error(e.Message);     
        }
    }

    5736.pastedimage1570612516812v1.png

    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.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 60 Most Valuable Professional

#2
11manish Profile Picture

11manish 23 Super User 2026 Season 2

#3
Travis South Profile Picture

Travis South 10

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans