Setting the default view for Business Process Flow lookups

Setting the default view for Business Process Flow lookups

John PhillipsProduct Updates

This short tutorial details the steps required to set the default view for a lookup column used in a Business Process Flow.

The problem

When using a lookup column on a form, the form editor provides the ability to change the default view:

Contact Field   Default View

However, this same functionality is not currently available is not available when using a lookup field as part of a Business Process Flow stage.

The solution

With a few lines of Javascript, the default view can be set by querying the view used by the field of the form and setting this as the default for the Business Process Flow.

What is required?

  • Some experience with Javascript and applying it to a model-driven form.
  • The field in question needs to be included on the main form so that the Javascript can read its settings to apply it to the Business Process Flow.

The Javascript

If your form already has some of your own custom javascript applied to it, you can simply add the snippet below to it. The elements that are in bold can be customised to suit your needs:

  1. the name of the function – in this case setDefaultAMView
  2. the lookup field you are referring to – in this case, str_accountmanager.

Everything else should remain as is – Business Process Flows automatically add the header_process_ prefix into the HTML, so you will need to keep this in the code.

function setDefaultAMView(executionContext) {
var formContext = executionContext.getFormContext();
formContext.getControl("header_process_str_accountmanager");
var defaultView = formContext.getControl("str_accountmanager").getDefaultView();
formContext.getControl("header_process_str_accountmanager").setDefaultView(defaultView);
}

Alternatively you can create a new Javascript file via the form editor:

Add Javascript Library

Once you have add the Javascript to the form, you will need to configure some additional settings to determine when the Javascript should run. Currently, this can only be done in the classic form editor.

  1. Switch to the classic form editor:
    Switch to Classic
  2. Click the Form Properties button:
    Form Properties
  3. Add a new onLoad event, referencing your Javascript file:
    Add Event
  4. Ensure that the ‘Pass execution context as first parameter’ is selected:
    Pass Execution Context
  5. Save and publish your form.

Your lookup field in the Business Process Flow should now now default to the same view as on the main form. If you are an existing client of Strategy 365 and wish to discuss this customisation for your own Dynamics 365 environment, then please get in touch with one of our experts.

Sign up to receive regular product & business updates direct to your inbox.
 
 
 
First Name*
 
 
Last Name*
 
 
 
Email Address*
 
 
 
 
 
 
 
 
 
Please see our Privacy Policy and Data Protection Policy for information on how we use your data