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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How to make "addPreSearch" optional in a BPF?

(0) ShareShare
ReportReport
Posted on by 30

I am currently customizing the OOB "Lead to Opportunity Sales Process" BPF. I have a requirement on the qualify stage to filter "Existing Contact?" by "Existing Account?" in a way that is identical to the filter options available on lookups on the main form. To achieve this I have written the function below and linked it to the OnChange event of ParentAccountId. The trouble with this implementation is it works too well. We want users to be able to turn off this filter if a contact needs to be added that is not associated with the specified account. 

On the main form you lookup field you can specify the "users can turn off filter" option which allows them to toggle a "Filter by related company" option in the "Look up record" modal. 
pastedimage1663268961538v1.png

Unfortunately, in the function I have shown below, users are not given the option to disable the filter. Is there a way I can enable this? I would like the option to show up with the same text in the same place, if the solution ends up being non-standard or hacky it will result in them simply not using it and lots of complaints.

Any help is appreciated.

function Filter_Contact(executionContext) {
    var formContext = executionContext.getFormContext();
    if (formContext.getControl("header_process_parentcontactid") != null) {
        formContext.getControl("header_process_parentcontactid").addPreSearch(function(executionContext) {
            var formContext = executionContext.getFormContext();
            var accountId = null;
            var filterBpf;

            if ((formContext.getControl("header_process_parentaccountid") != null) && (formContext.getControl("header_process_parentaccountid").getAttribute().getValue() != null)) {
                accountId = formContext.getControl("header_process_parentaccountid").getAttribute().getValue()[0].id;
                if (accountId != null || accountId != undefined) {
                    filterBpf = "";
                    formContext.getControl("header_process_parentcontactid").addCustomFilter(filterBpf);
                }
            } else {
                console.log("Unable to find parentaccountid");
            }
        });
    } else {
        console.log("Unable to find parentcontactid");
    }
}

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi DorienM,

    This setting can not work for the field on the BPF.

    So as a workaround, you could add a two option field like "filter contacts". Then you can filter contacts or not base on its value.

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

News and Announcements

Season of Giving Solutions is Here!

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 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 76

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 53 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 40 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans