
I have seen various threads on getting a lookup to filter in the BPF. Using the example from here:
( ) How to Filter Lookups in a Dynamics 365 Business Process Flow - Microsoft Dynamics CRM Community
I actually want to do exactly the same thing but am confused. This is to filter the contact lookup on the BPF based on the account selected.
These fields are primarycontactid and customerid.
This is what I am trying to use, does this look correct?
function filterBpfLookup = function(formContext) {
if (formContext.getControl("header_process_primarycontactid") !=null) {
formContext.getControl("header_process_primarycontactid").addPreSearch(filterDefinition);
}
function filterDefinition = function(formContext) {
var accountId = null;
var accountLookup;
var filterBpf;
if (formContext.getControl("header_process_primarycontactid") != null &&
formContext.getControl("header_process_primarycontactid").getAttribute().getValue() != null)
{
accountLookup = formContext.getControl("header_process_customerid").getAttribute().getValue();
accountId = accountLookup[0].id;
if (accountID != null || accountID != undefined) {
filterBpf = ""
"" "";
formContext.getControl("header_process_primarycontactid").addCustomFilter(filterBpf);
}}}}
Please note that I cannot write JScript to save my life.
Also if correct, do I add this to the onLoad of the form or somewhere else?
I also cannot write JScript, so kudos to you for taking a stab at this! I have been craving this functionality for a while. My workaround has been to just place the lookup field I want to filter directly on the form itself, that allows me to filter it how I need. I do have some scenarios where I don't need a user to complete that field until they reach a certain point of the business process flow, so I'll create a business rule to Show/Hide or Require/Unrequire the lookup field at the appropriate times. It's worked well for us so far.