Skip to main content

Notifications

Dynamics 365 general forum
Suggested answer

How to make "addPreSearch" optional in a BPF?

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to make "addPreSearch" optional in a BPF?

    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

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans