Business Process Flows in Dynamics CRM 2013: Hiding/Showing a Section Based on the Current Stage

Business processes in Microsoft Dynamics CRM 2013 are great out-of-the-box, but there are also a few things that we can do in terms of extending the functionality of the stages with some customizations.

In this blog I'll show how to conditionally hide/show a business process flow section based on the current stage. For example, let’s say that for some business process flows, before entering information on a new lead you want to validate that this lead does not already exist in CRM as an account or contact:

CRM 2013 Business Process Flow Customization

To drive home this point to your end users, on the lead form, you will not show ANY sections unless this stage has been addressed. Therefore, if you are in the “INITIAL” stage as shown above, then nothing should be visible on the lead form until you progress to the next stage (in my example the stage name is GATHER).

CRM 2013 Business Process Flow Customization 2

Here is how this can be accomplished using JavaScript:

Identify the GUID of the Process Stage.

The stage is available for any business process enabled entity as the field stageid with the type of unique identifier:

CRM 2013 Business Process Flow Customization 3

Therefore using the Xrm page methods, we can get its value by calling getAttribute and then getValue:

var stageID = Xrm.Page.getAttribute("stageid").getValue();

stageID then is the 32-digit globally unique identifier that is returned by the Xrm method since its type is unique identifier as we saw in the customizations screenshot.

In order to conditionally hide sections when the stage is INITIAL and not GATHER, we will be comparing the current stage ID—the selected stage ID when you open the form—against the value of the INITIAL stage ID.

So, you will need to get this value, of course, in order to compare it.

The easiest way is to create a function onLoad where you can use the alert to get the value:

function hideStage() {

var stageID = Xrm.Page.getAttribute("stageid").getValue();

alert(stageID);

}

After creating the JavaScript file and adding this function, add the getText function to the list of functions that are called onLoad, save and publish.

When you open up a lead, you will see the alert of the current stageID:

CRM 2013 Business Process Flow Customization 4

Make note of what is shown in the alert box as you will be needing this value to hide the field.

After you make note of the GUID, use the Xrm page methods found here (http://msdn.microsoft.com/en-us/library/gg327828.aspx) to modify your function. Your alert should look somewhat like this:

function hideStage() {

var stageID = Xrm.Page.getAttribute("stageid").getValue();

if (stageID == 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx') {
Xrm.Page.ui.tabs.get("").setVisible(false);
Xrm.Page.ui.tabs.get("").setVisible(false);

}

Else {

Xrm.Page.ui.tabs.get("").setVisible(true);
Xrm.Page.ui.tabs.get("").setVisible(true);

}
}

Now, also add this function to the onSave of the form, and that’s it! You will now be able to conditionally hide/show the tabs on the form based on the stage ID.

Feel free to give me a ring if you would like additional information about Dynamics CRM 2013 and Business Process Flows.

See also: Using Out-of-the-Box Field Level Security to Apply Security to Business Process Flows in Dynamics CRM 2013

Written by:
Henry Lin, CRM Consultant, FMT Consultants

Posted by: 

©
2023
 FMT Consultants
|
Privacy Policy
X
FMT

Contact Us

X
FMT

Newsletter Sign-up

menu linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram