What happens when you force fields on BPF to be required programatically or using Business Rule

I had a requirement where I needed to make certain fields on BPF as required.

So, I tried accessing the control using Xrm.Page.getControl(“header_process_description”) and then getAttribute().setRequiredLevel(“required”) on it would serve my purpose. But actually, not!

To set perspective, the code runs and make the field required too. But there’s a catch!

Required fields on the BPF are supposed to throw an error when you are trying to move to the next stage without filling in the required fields.

But, using the code I’m talking about above (sample shown below), will force you to save the form entirely. Let alone moving the stages further.

jsCode

That when ‘How Did You Hear About Us?’ field has Employee Referral as value, make Purchase Process field required.

empoyeeReferalSet

Field is on the BPF

fieldOnBPF

But prompts me to save the form
promptToSave

 

Workaround

The easiest workaround to this is using the conditional branching of your business process flow –

You can use conditional branching of the BPF itself – You can replicate the same stage twice, one having your required field and other having that same field as optional.

bpfBranching

However, limitations I found with this approach is –

  1. I couldn’t use the same for the first stage of the BPF –
    limitation1
  2. The condition had to be from the previous stage itself
    limitation2

P.S. Business Rules isn’t a solution as well. Also, I tried to inverse the logic by first making the field required in the BPF itself and then trying to make it not required using code. That doesn’t work either.

Hope this gives an idea. Let me know if you have other suggestions! 😊

 

Advertisement

Understanding Xrm.Page Object Model

Xrm.Page Namespace

When writing form scripts, we will interact with objects from the Xrm.Page namespace to perform the following actions:

  1. Get/Set attribute values.
  2. Show/Hide user interface elements.
  3. Reference multiple controls per attribute.
  4. Access multiple forms per entity.
  5. Manipulate form navigation items.

 

Xrm.Page Object Hierarchy

Context – Provides methods to retrieve information specific to an organization, a user, or parameters that were passed to a form as a query string.

Data – Provides access to the entity data and methods to manage data in the form.

UI – Contains methods to retrieve information about the user interface, in addition to collections for several sub components of the form.
xrm.PageObjectModel

 

Execution Context

When you register a function for an event handler, CRM lets you pass the execution context object as the first parameter to the function.

This object contains methods that allow you to managed variables you wish to share with other event handlers.

 

Collections

attributes:

  1. Page.data.entity.attributes collection provides access to each entity attribute that is available on the form. Only those attributes that correspond to fields added on the form are available.

 

controls:

  1. controls provides access to each control on the form.
  2. controls provide access to each control that have more than one control for an attribute available on the form.
  3. controls provides a collection of controls found in a section.

 

  1. items:
  2. Page.ui.navigation.items collection provides access to navigation items that are defined using the navigation area of the form editor.

 

  1. items:

If multiple forms are associated with an entity, each form can be associated with a security role and if security roles of a user enable users to see more than one form, they can select from a collection of Xrm.Page.ui.formSelector.items. A form definition is available in this case.

 

tabs:

  1. Page.ui.tabs provides access to collection of each of the tabs present on the form.

 

sections:

A tab can be organized by using more than one section. The tab sections collection provides access to these sections.

 

Hope this overview was helpful to you!