PowerObjects Blog 

for Microsoft Business Applications


Setting Visibility of a Business Process Flow with JavaScript in Dynamics CRM 2015

Post Author: Joe D365 |

The business process flows that were introduced with CRM 2013 are a great way to walk a user through a specific process, related to an entity in Microsoft Dynamics CRM. However, there are times when a business process flow is useful for one team, but maybe not for another. What if, for example, you have a general account form for the entire team, but then a separate account form for the billing team? A business process flow that walks you through creating a support agreement for the account might be useful for the users who use the general account form, but maybe not for the billing team. Luckily, there is a quick and easy way to hide the business process flow, using some basic JavaScript.

First, you'll want to create a two option type field that you will set if you'd like to hide the business process flow. In my case, I've created a field called "Hide BPF", and set the default value to "Yes".

Setting Visibility of a Business Process Flow with JavaScript in Dynamics CRM 2015

Next, place the field on the form that you'd like to hide the business process flow on. Note that the JavaScript listed below only runs when the field is on the form, and will hide the BPF when the field is either blank or true (yes). So what you could do is place the field on the form in an "administrator" section, or something similar, as a read-only field. That way, the field will always be blank or yes, and no one can change it, which means that any form this field is on, will hide the BPF.

After you've created the "Hide BPF" field, create a web resource containing the JavaScript to hide the business process flow. When you create the web resource, name it appropriately, and paste the following JavaScript into the web resource content.

 

function hideBusinessProcessFlow() {

Xrm.Page.ui.process.setVisible(false);

}

 

function showBusinessProcessFlow() {

Xrm.Page.ui.process.setVisible(true);

}

 

function showHideBusinessProcessFlow() {

if (Xrm.Page.getAttribute("po_hidebpf").getValue() == false) {

showBusinessProcessFlow();

}

else {

hideBusinessProcessFlow();

}

}

 

Then, navigate to the form where you'd like to hide the business process flow and navigate to the form properties, within the form customizations. Add the form library (web resource you created in the last step) and create a new Form OnLoad event, that calls the function above.

Save and publish your customizations. Now, when users are using this form, the business process flow will be hidden.

Setting Visibility of a Business Process Flow with JavaScript in Dynamics CRM 2015

Whereas on forms where this field is not used, the business process flow will show as expected.

Setting Visibility of a Business Process Flow with JavaScript in Dynamics CRM 2015

Credit: Thank you for Ms. Dynamics CRM for the article, which helped get this blog together.

Make sure to stop by our main blog page for even more Dynamics CRM fun! Or if you are interested in learning more about CRM 2015, we have an entire page dedicated to bringing the latest and greatest information to you!

Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

6 comments on “Setting Visibility of a Business Process Flow with JavaScript in Dynamics CRM 2015”

  1. You shouldn't use the DOM when manipulating CRM forms. And there is already support for what you are trying to do in the Xrm.Page library.

    1. Because once the BPF is attached to a record... it will show to a user that has access to that record, but not access to that BPF

      1. Hi Tim,
        Can you explain what you mean by "...it will show to a user that has access to that record, but not access to that BPF".

  2. Hi Joe.

    Thank you for your post.

    However, after to use your script to hide the BPF in Dynamics 2015 on line, I´m facing a problem: after to save the opportunitty by the first time (to create an opp), the BPF is showed again. I put an alert in the on save event and I note that the load evend is called 2 times. But, at the end of the process, the BPF is showed.

    Any sugestion about this question?

    Thank´s in advance.

    Marcelo Rigoni

  3. thanks alot very nice but I need critical feature I Need to put security role for specefic stage is this any workaround for it

PowerObjects Recommends