Hiding and Showing a Dynamics CRM Business Process Flow with Javascript

Business Process Flows (BPF for short) are used in CRM systems to guide users towards a desired outcome by defining steps for users to follow. In some instances, these processes are added to entities, such as the Lead entity, and can be very useful and for other instances they may not be needed. During a recent project an entity was created which needed to make us of a BPF only when a certain field was populated. When that field contained data the BPF would appear near the top of the form, and when the field was empty it would disappear.

By using Javascript, you can provide the functionality of both, detecting if a specific field contained data and hiding or showing a BPF on the form. To determine whether or not the specified field was populated I used the ‘Xrm.Page.getAttribute(“field_name”).getValue()’ which would return a value if the field contained data or would return null if it did not. In the example below I replaced ‘field_name’ with ‘new_playerpositions’ which would get the value of the ‘Player Position’ field. At the moment this call is returning null.

image thumb Hiding and Showing a Dynamics CRM Business Process Flow with Javascript

To hide or show the BPF, you can use the function call ‘Xrm.Page.ui.process.setVisible()’ which would set the visibility of the BPF. Because only one BPF should be visible on a form at a time there is no need to use a process id. Passing a Boolean to ‘setVisible()’ would result in the BPF hiding or showing, where true would show the BPF and false would hide it. If you wanted to collapse or expand the BPF Xrm.Page.ui.process also has a function call ‘setDisplayState()’ which takes a string of either ‘collapsed’ or ‘expanded’. The screenshot below shows the form when the ‘Player Position’ field is populated, resulting in the setVisible() function call being set to true.

image thumb 1 Hiding and Showing a Dynamics CRM Business Process Flow with Javascript

Let’s block ads! (Why?)

Magnetism Solutions Dynamics CRM Blog