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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtering Lookups on the Business Process Flow fields

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Have you tried something like:

    function preFilterLookup() {

    if (Xrm.Page.getControl("header_process_contractid") == null)

    return;

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

    addLookupFilter();

    });

    }

  • MituCRMing Profile Picture
    274 on at

    I am trying to do the same thing, well the first one. I used the above code and modified it per my fields name but the filter isn't working. Do I need to register onChange?

  • JaiG Profile Picture
    on at

    I did it onLoad. Been working fine for me.

    Do you want to paste your script?

  • MituCRMing Profile Picture
    274 on at

    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);

    }

    }

  • JaiG Profile Picture
    on at

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

    What error are you getting?

  • MituCRMing Profile Picture
    274 on at

    The code isn't doing anything....

  • JaiG Profile Picture
    on at

    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
    274 on at

    This is my findings from debugging

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

  • JaiG Profile Picture
    on at

    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
    274 on at

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

    Xrm.Page.getControl("new_facilitytypeid");

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans