Jaa


Write scripts for business process flows

 

Applies To: Dynamics CRM 2015

With Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update there is a client-side object you can use to interact with business process flows in your scripts. The Xrm.Page.data namespace is extended to include methods under Xrm.Page.data.process. The Xrm.Page.ui namespace is extended to include methods under Xrm.Page.ui.process.

In this topic

Structure of business process flows

Actions that can be automated

Events for business process flows

Structure of business process flows

Business process flows consist of a series of stages, each containing a number of steps. Only one stage is the active stage. When the required steps in each stage are complete, the process can move on to the next stage and it becomes the active stage. Which stage is next can be defined based on conditions in the business process flow as shown in the following diagram.

Business Process Flow Objects

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: TechNet: 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. 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_getEnabledProcesses to retrieve information about enabled processes that the user can choose for the entity. Then use Xrm.Page.data.process. 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_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. 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_moveNext.

  • Move to the previous stage and make it the current active stage.
    Use Xrm.Page.data.process. 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_movePrevious.

  • Select a stage to view the status of the steps in the stage.
    Use Xrm.Page.data.process. 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_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 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_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 6881e99b-45e4-4552-8355-2eef296f2cd8#BKMK_setValue method to set the value.

  • Detect whether a step is required
    Use the step 6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_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. 1468bab0-f6b3-4320-a60c-a88c9d4fcf1f#BKMK_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. 1468bab0-f6b3-4320-a60c-a88c9d4fcf1f#BKMK_setVisible, you can control whether to display the business process flow control.

  • Skip to a valid completed stage.
    Use Xrm.Page.data.process.6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_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.6b79eb8c-8293-4d3a-a3a7-ea35157cde37#BKMK_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 (d88d5f21-6385-443b-91f2-0ec0c16b1324#BKMK_OnStageChange) or when a stage is selected (d88d5f21-6385-443b-91f2-0ec0c16b1324#BKMK_OnStageSelected).

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 form OnLoad event.. More information: f451f339-bcee-4260-9904-abc8c0efa153#BKMK_BPFControl

See Also

Use the Xrm.Page object model
Xrm.Page.data.process (client-side reference)
Sample: Xrm.Page.data.process.getEnabledProcesses
Sample: Xrm.Page.data.process.getActivePath
f451f339-bcee-4260-9904-abc8c0efa153#BKMK_BPFControl
TechNet: Business process flows

© 2016 Microsoft. All rights reserved. Copyright