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)

Filtered lookup BPF

(0) ShareShare
ReportReport
Posted on by

Hello Everyone!

I'm trying to replicated a filtered lookup behavior on "Phone Call" in the business process flow section.

I've got on the "Phone Call" 2 lookup fields as follow:

1. Service Call type (new_productfamily).

2. Service Type (new_servicetype).

A service type records holds within it the service call type value as well.

And basically, once service call type = service call type (on service type record) fetch service type value.

Once I choose a service call type I've got Service type filtered appropriately. 

However, I've added those lookup to my process flow and alas the filtering doesn't take on them.

So I've snooped around and it's not possible oob and require some js.

I was looking at this script below but unable to run it.

Where/which event handler am I putting this in (onChange of the "Service Type" lookup??)

function filterLookup() {
//Check if the control exist on the form
if (Xrm.Page.getControl(“header_process_new_servicecalltype”) != null) {
// add the event handler for PreSearch Event
Xrm.Page.getControl(“header_process_new_servicecalltype”).addPreSearch(addFilter);
}
}
function addFilter() {
var sCallTypeId = null;
var sCallTypeLookup;
var fetchQuery;
try {
//Check if control exist on form
if (Xrm.Page.getControl(“header_process_new_servicecalltype”) != null && Xrm.Page.getControl(“header_process_new_servicecalltype”).getAttribute().getValue() != null) {
//Get Service Call Type lookup value
sCallTypeLookup = Xrm.Page.getControl(“header_process_new_servicecalltype”).getAttribute().getValue();
//Get the Service Call Type id
sCallTypeId = sCallTypeLookup[0].id;
}
//Build fetch
if (sCallTypeId != null || sCallTypeId != undefined) {
fetchQuery = “<filter type=’and’>” +
“<condition attribute=’new_servicetypeid’ operator=’eq’ value=’” + sCallTypeId + “‘ />” +
“</filter>”;
//add custom filter
Xrm.Page.getControl(“header_process_new_servicetype”).addCustomFilter(fetchQuery);
}
} catch (e) {
Xrm.Utility.alertDialog(“addFilter Error: ” + (e.description || e.message));
}
}


Thank you,

- Bod

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at

    Hi Bod,

    Please check the below articles which explains how to configure filtering in BPF.

    http://www.inogic.com/blog/2014/07/how-to-apply-script-on-header-fields-and-bpf-fields/

    https://community.dynamics.com/crm/b/misscrm360exploration/archive/2014/08/24/crm-2013-using-addcustomfilter-to-get-filtered-lookup-field-based-on-linked-entity

    To answer your question, trigger filterLookup() function OnLoad event.

    Cheers,

    Nadeeja

    If the answer solves your problem, please mark as Verified. Thanks.

    My Blog: http://dyn365apps.com/ - Follow me on Twitter: https://twitter.com/dyn365apps

    LinkedIn: https://www.linkedin.com/in/nadeeja

  • Community Member Profile Picture
    on at

    Aside from the fact that I get a reference error (filterLookup is not defined at eval..)

    I'm able to filter the lookup that's on the actual form and it's populating just fine on the process flow.

    But on form load if a I hit the process flow lookup straight up it's just not filtering.

    I've added the script onLoad event but I get the error above.

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at

    Hi Bod,

    Below are code snippets of when I implemented BPF Lookup filtering recently.

    application.RunOnLoad function is configured to get triggered OnLoad.

    application.RunOnLoad = function () {
        application.BpfManagerFilteredLookup();
    }

    Add the event handler for PreSearch Event

    application.BpfManagerFilteredLookup = function () {
        // Field: header_process_xx_approving_manager
        // Check if the control exist on the form
        if (Xrm.Page.getControl("header_process_xx_approving_manager") != null) {
    
            // add the event handler for PreSearch Event
            Xrm.Page.getControl("header_process_xx_approving_manager").addPreSearch(application.BpfManagerAddFilter);
    
        }
    }

    The Filter.

    application.BpfManagerAddFilter = function () {
        var fetchQuery;
    
        try {
            //Check if control exist on form
            if (Xrm.Page.getControl("header_process_xx_approving_manager") != null) {
    
                //Build fetch
                fetchQuery = "<filter type='and'>" +
                                "<filter type='and'>" +
                                "<condition attribute='xx_is_manager' operator='eq' value='1' />" +
                                "<condition attribute='statecode' operator='eq' value='0' />" +
                                "</filter>" +
                            "</filter>";
    
                //add custom filter
                Xrm.Page.getControl("header_process_xx_approving_manager").addCustomFilter(fetchQuery);
            }
        }
        catch (e) {
                Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message));
        }
    }

    Hope this helps.

    Cheers,

    Nadeeja

    If the answer solves your problem, please mark as Verified. Thanks.

    My Blog: http://dyn365apps.com/ - Follow me on Twitter: https://twitter.com/dyn365apps

    LinkedIn: https://www.linkedin.com/in/nadeeja

  • Community Member Profile Picture
    on at

    So my query needs to be based on dynamic value (the value in service call type) and not a static string value.

    After the user set the "Service Call Type" lookup the "Service Type" lookup needs to show filtered results.

    The Service Type entity/form holds in it the service call type as well.

    6266.Capture.PNG

    I'm trying to fetch which records (I have multiple) in service type have the selected service call type in them.

    Also, it's important to note that the script runs on the phone call entity. When a user initiate a new phone call the Service Call type is null/empty still, So I'm not sure how/why the script runs onLoad.

  • Verified answer
    Nadeeja Bomiriya Profile Picture
    6,804 on at

    Hi Bod,

    It doesn't matter if the filter is static or dynamic.  What we are doing OnLoad event is configuring an event handler.  The function will get called every time, PreSearch event is triggered.

    In my example, inside application.BpfManagerAddFilter() function, I could have used the selected value of a lookup and use that as part of the filter criteria.

    For example,

    Fetch Service Call Type Lookup Id

    //Get Service Call Type lookup value
    
    serviceCallTypeLookup = Xrm.Page.getControl(“header_process_servicecalltype”).getAttribute().getValue();
    
    //Get the servicecalltypeid
    
    serviceCallTypeId = serviceCallTypeLookup[0].id;

    Then use it in the filter.

    if (Xrm.Page.getControl("header_process_xx_approving_manager") != null && serviceCallTypeId != null) {
    
                //Build fetch
                fetchQuery = "<filter type='and'>" +
                                "<filter type='and'>" +
                                "<condition attribute='statecode' operator='eq' value='0' />" +
                                "<condition attribute='xx_servicecalltypeid' operator='eq' value='” + serviceCallTypeId + “‘ />" +
                                "</filter>" +
                            "</filter>";
    
                //add custom filter
                Xrm.Page.getControl("header_process_xx_approving_manager").addCustomFilter(fetchQuery);
            }

    Cheers,

    Nadeeja

    If the answer solves your problem, please mark as Verified. Thanks.

    My Blog: http://dyn365apps.com/ - Follow me on Twitter: https://twitter.com/dyn365apps

    LinkedIn: https://www.linkedin.com/in/nadeeja


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