Skip to main content

Notifications

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

  • 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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans