Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Filtering Lookups on the Business Process Flow fields

Posted on by

Hello,

I understand that to get the fields in the business process flow to filter you have to do it using JS and add a custom filter to those fields. The fields are named as header_process_<fieldname>.

I have this working. BUT my problem is that if I load a Case that was created before we started using BPFs, it raises an error when trying to GetControl header_process_<fieldname>.

How do I add a check before the getcontrol to see if the field actually exists on the form?

Here is my script:


function preFilterLookup() { Xrm.Page.getControl("header_process_contractid").addPreSearch(function () {
addLookupFilter();
});
}
function addLookupFilter() {
var lookupobject = Xrm.Page.getAttribute("customerid");
var value = lookupobject.getValue();
var name = value[0].name;
var id = value[0].id;

if (id != null) {
fetchXml = "<filter type='and'><condition attribute='customerid' operator='eq' value='" + id + "' /></filter>"; Xrm.Page.getControl("header_process_contractid").addCustomFilter(fetchXml);
}
}

Also Microsoft, WHY can't these fields filter out of the box. Ridiculous that I have to use JS to add custom filter to these header fields.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filtering Lookups on the Business Process Flow fields

    Hi ,

    I used this on Load method

       if (Xrm.Page.getControl("header_process_willis_currentbrokerid") != null) {

           Xrm.Page.getControl("header_process_willis_currentbrokerid").addPreSearch(filterDefinition);

       }

    And this is filterDefinition function

    function filterDefinition() {

       var accountId = null;

       var accountLookup;

       var filterBpf;

       //formContext = executionContext.getFormContext();

       if (Xrm.Page.getControl("header_process_willis_currentbrokerid") != null &&

           Xrm.Page.getControl("header_process_willis_currentbrokerid").getAttribute().getValue() != null) {

           accountLookup = Xrm.Page.getControl("header_process_parentaccountid").getAttribute().getValue();

           accountId = accountLookup[0].id;

           if (accountId != null || accountId != undefined) {

               filterBpf = "<filter type='and'>" +

                   "<condition attribute='customertypecode' operator='eq' value='200000' />" +

                   "</filter>";

               if (Xrm.Page.getControl("header_process_willis_currentbrokerid") != null) {

                   Xrm.Page.getControl("header_process_willis_currentbrokerid").addCustomFilter(filterBpf);

               }

           }

       }

    }

    I am not getting any error but also it is not filtering lookup field. Can you help me please?

    Thanks,

    Mayur

  • JaiG Profile Picture
    JaiG on at
    RE: Filtering Lookups on the Business Process Flow fields

    So to Troubleshoot I typically see if I am able to get all variables. And I display the variable I think I am not getting in a popup.

    So alert(value); should show the value variable defined below in a popup box, thus verifying you are getting the variable.

    If that works move on to the next one (name, id etc.)

    function preFilterLookup() {

    Xrm.Page.getControl("header_process_new_facilitytypeid").addPreSearch(function () {

    addLookupFilter();

    });

    }

    function addLookupFilter() {

    var lookupobject = Xrm.Page.getAttribute("new_facilitylocationid");

    var value = lookupobject.getValue();

    var name = value[0].name;

    var id = value[0].id;

    if (id != null) {

    fetchXml = "<filter type='and'><condition attribute='new_facilitylocationid' operator='eq' value='" + id + "' /></filter>";

    Xrm.Page.getControl("header_process_new_facilitytypeid").addCustomFilter(fetchXml);

    }

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Filtering Lookups on the Business Process Flow fields

    Refer this:

    www.inogic.com/.../how-to-apply-script-on-header-fields-and-bpf-fields

  • MituCRMing Profile Picture
    MituCRMing 270 on at
    RE: Filtering Lookups on the Business Process Flow fields

    what do you mean by that? Do you mean this? This also returned null

    Xrm.Page.getControl("new_facilitytypeid");

  • JaiG Profile Picture
    JaiG on at
    RE: Filtering Lookups on the Business Process Flow fields

    Can you try querying the non header process field and see if that returns a value?

    So store the attribute as a variable then display it in a popup.

    Sounds like the header process field doesn't exist/is spelled wrong.

  • MituCRMing Profile Picture
    MituCRMing 270 on at
    RE: Filtering Lookups on the Business Process Flow fields

    This is my findings from debugging

    Xrm.Page.getControl("header_process_new_facilitytypeid"); is coming as  null.

  • JaiG Profile Picture
    JaiG on at
    RE: Filtering Lookups on the Business Process Flow fields

    So when you go to the field you want filtered and click enter, no error shows up?

    I would put in a popup box that pops up with a value of the field you are getting to test.

    alert("I am an alert box!");

  • MituCRMing Profile Picture
    MituCRMing 270 on at
    RE: Filtering Lookups on the Business Process Flow fields

    The code isn't doing anything....

  • JaiG Profile Picture
    JaiG on at
    RE: Filtering Lookups on the Business Process Flow fields

    Looks fine to me...but I'm also not an expert.

    What error are you getting?

  • MituCRMing Profile Picture
    MituCRMing 270 on at
    RE: Filtering Lookups on the Business Process Flow fields

    Sure.

    function preFilterLookup() {

    Xrm.Page.getControl("header_process_new_facilitytypeid").addPreSearch(function () {

    addLookupFilter();

    });

    }

    function addLookupFilter() {

    var lookupobject = Xrm.Page.getAttribute("new_facilitylocationid");

    var value = lookupobject.getValue();

    var name = value[0].name;

    var id = value[0].id;

    if (id != null) {

    fetchXml = "<filter type='and'><condition attribute='new_facilitylocationid' operator='eq' value='" + id + "' /></filter>";

    Xrm.Page.getControl("header_process_new_facilitytypeid").addCustomFilter(fetchXml);

    }

    }

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans