Filtering Records on BPF unlike on Form – D365
Introduction:
Working with D365 is best when you’re trying to use as much OOB stuff as possible. Simplest configurations like selecting a view for your Lookup field is easily possible on the D365 Form.
However, this is not possible on the fields on the Business Process Flow
Use of addPreSearch() and addCustomFilter() on BPF Fields:
Now, since you have this field on the BPF and want to add filter to Lookup records, you’ll need to use JS customization to achieve this and add your filter’s criteria in the code to show results as expected.
- Let’s say you see all the lookup records on the field on the BPF
2. I want to see only Semi Annually type of Plans on the Lead. And I can’t simply do this from the Field’s Properties like on the form. Because, it’s not available.3. Hence, I’ll write JS code as follows to achieve this:
// JavaScript source code var oOFFormCustomization = { preFiltering: function () { "use strict"; if (Xrm.Page.getControl("header_process_cf_defaultplan") != null) { Xrm.Page.getControl("header_process_cf_defaultplan").addPreSearch(oOFFormCustomization.preSearchProductFamily); } else return; }, preSearchProductFamily: function () { "use strict"; var fetchQuery = '<filter type="and"> <condition attribute="cf_plantype" operator="eq" value="979570001" /><condition attribute="statecode" operator="eq" value="0" /></filter>'; Xrm.Page.getControl("header_process_cf_defaultplan").addCustomFilter(fetchQuery); } };
4. And I register the method on Page Load of the Form.
5. And I see these results once it successfully filters!