CRM 2015 – New Features – Write form scripts that interact with business process flows
Stages can be associated with specific related entities, so a business process flow can span multiple entities. The business process remains the same and leads the user to a desired conclusion. More information: Customization Guide topic: Business Process Flows Actions that can be automated Normally, progressing along the business process depends on user input. As a developer, you can perform the same actions programmatically in form scripts. 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 useXrm.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 setValuemethod 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.
There are also some things you can do as a developer that a user cannot perform. 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). Neither of these new events provide a user interface to register your event handlers. You must use methods provided to add or remove handlers for these events in the formOnLoad event.. More information: Business Process Flow control events