Sonoma Partners Microsoft CRM and Salesforce Blog

CRM 2015 – Scripting Options for Business Process Flows

Since the release of business process flows in CRM 2013, we’ve been clamoring for more extensibility from a scripting standpoint.  With the release of CRM 2015 Microsoft has added several new methods to the javascript API that allow developers to greatly extend the out-of-the-box business process flows capability.

The following is a list of the new API methods from this MSDN article.  We are particularly most excited about the ability to dynamically hide/show the business process flow control.

Change the process when there are more than one process available for the entity.
Use Xrm.Page.data.process.getEnabledProcesses to retrieve information about enabled processes that the user can choose for the entity. Then use Xrm.Page.data.process.setActiveProcess to make one of the enabled processes the active one.

Move to the next stage when all required steps are completed to make it the current active stage.
Use Xrm.Page.data.process.moveNext.

Move to the previous stage and make it the current active stage.
Use Xrm.Page.data.process.movePrevious.

Select a stage to view the status of the steps in the stage.
Use Xrm.Page.data.process.getActivePath to retrieve information about the stages that have been completed, the current active stage, and valid stages available from the current active stage. Examine the steps included in that stage and compare the corresponding form attribute values to determine whether they are completed.

Complete a step
Steps are completed when the corresponding data in the form is entered. You can determine the attribute using the step getAttribute method. This will return the logical name of the attribute. Then use Xrm.Page.getAttribute to retrieve attribute from the Xrm.Page.data.entity.attributes collection and then use the attribute setValue method to set the value.

Detect whether a step is required
Use the step isRequired method to determine if a step is required by the business process flow.

Expand or collapse the business process flow control
Use Xrm.Page.ui.process.setDisplayState.

Hide the process control
Use Xrm.Page.ui.process.setVisible, you can control whether to display the business process flow control.

Skip to a valid completed stage.
Use Xrm.Page.data.process.setActiveStage to set one of the valid completed stages for the current entity.

Query the process definition including stages not currently visible
Use Xrm.Page.data.process.getActiveProcess to query the definition of the business process flow, including stages that might not be visible because of branching logic in the process.

Events for business process flows
You can interact any event provided by the form with business process flows, but two new events allow you to execute code based on events just for the business process flow control. You can execute code when the active stage of a business process flow changes (OnStageChange event) or when a stage is selected (OnStageSelected event).

The SDK team also provided a couple great samples for the new scripting methods.  Check out this sample on how to retrieve information about the enabled processes for an entity and this sample on retrieving information about the stages and steps in the active business process flow path.

Topics: Microsoft Dynamics CRM Microsoft Dynamics CRM 2015 Microsoft Dynamics CRM Online