SristiJain
SristiJain

Reputation: 13

Custom View gets cleared after clicking on 'Advanced Lookup' for Lookup field

I have a lookup field for which I need to filter values based on some condition.

I call a function on Form OnLoad to add Custom View to it which works fine.

var viewId = Xrm.Page.getControl("lookupfield").getDefaultView();

formContext.getControl("lookupfield").addCustomView(viewId, "entityname", "viewname", fetchXML, layoutXML, true);

However when I click on 'Advanced Lookup', click done, and then go back to the form, the custom view clears up and filtering doesn't work.

I also tried addCustomFilter :

    setValues: function(executionContext) {
         var formContext = executionContext.getFormContext();
         formContext.getControl("attributename").addPreSearch(filterValues);
    },

    filterValues: function() {
        var filter = //the same filter which I use for addCustomView,it works fine
        formContext.getControl("attributeName").addCustomFilter(filter, "entityName");
    }

It fires, doesn't throw any error, but simply doesn't filter the values.

I also tried adding the filterValues function inline but in vain.

Upvotes: 0

Views: 119

Answers (1)

mr.mindspace
mr.mindspace

Reputation: 109

To filter the results of a lookup, you should use formContext.getControl("lookupfield").addCustomFilter(filter, "entitylogicalname") instead.

The filter parameter should be a fetchXml string of the filter you want to apply to the lookup field results.

See https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/controls/addcustomfilter

Upvotes: 0

Related Questions