Поделиться через


Write scripts for business process flows

 

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

With Microsoft Dynamics 365 (online & on-premises) 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.

Starting with December 2016 update for Dynamics 365 (online and on-premises), different business process flow definitions can be associated with different roles and the instances can run concurrently against the same entity record. Users can switch between concurrent business process instances and resume their work at a current stage in the process.

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.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 process instances the active one or create a new process instance.

  • Change the process instance for an entity record
    Use getProcessInstances to retrieve information about all the process instances for an entity record and setActiveProcessInstance to set a process instance as the active instance.

  • 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.

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

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.

  • 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 the following 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).

  • You can execute code when the status of a business process flow instance changes (OnProcessStatusChange event). A business process flow instance can have one of the following statuses: Active, Finished, or Aborted.

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:  Business Process Flow control events

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
Business Process Flow control events
TechNet: Business process flows

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright