Skip to main content

Notifications

Announcements

No record found.

Service | Customer Service, Contact Center, Fie...
Suggested answer

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

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
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: AddSerarchFilter method is not working in the D365 v9 Unified interface(Model Driven App)

    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

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: AddSerarchFilter method is not working in the D365 v9 Unified interface(Model Driven App)

    Hi,

    Are you getting any error message?

  • Suggested answer
    Fubar Profile Picture
    Fubar 2,750 on at
    RE: AddSerarchFilter method is not working in the D365 v9 Unified interface(Model Driven App)

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans