Create Workflows with Event Phase
The Cmc.Nexus eventing system was enhanced to raise events for custom service methods in 3 phases (Validation, Execution, and Completion). Workflow Composer 3.0 and later allows you to select the applicable Event Phase for service-based (non-CRUD) events.
Previously, all workflows were executed during the Execution Phase of a business process. There was no option to add a workflow to be used as validation for an event. For example, it was not possible to inject business logic into a transaction to cancel the execution of a workflow if the custom validation failed. Now, Workflow Composer allows you to select the Validation, Execution, or Completion Phase when creating a workflow.
For any custom service-based workflows created before this enhancement, the workflows will continue to run during the Execution Phase.
Event Phase Selection
Workflows Based on Custom Services
The "New Event Driven Workflow" window in Workflow Composer displays the Event Phase options when you to select a service-based event associated with a custom service method, such as the Post Account Transaction Charge Event associated with the Student Account Transaction Service.
Under "Workflow to run during Event Phase" select one of the following:
- Validation Phase
- Execution Phase
- Completion Phase
The selected Event Phase will be embedded into the .xaml file and cannot be modified. Similar to the “Entity” and “Event”, the "Event Phase" cannot be modified once created.
The event pipeline Execution Order is as follows:
- Execute workflows published to the Validation Phase for the custom event name.
- If the pipeline is not canceled, execute C# registered handlers for the custom event name.
- If the pipeline is not canceled, execute workflows published to the Execution Phase for the custom event name.
- If the pipeline is not canceled, execute workflows published to the Completion Phase for the custom event name.
Workflow event handlers at the Validation Phase are registered at sequence (negative) -1048576 to ensure that they run first. This allows the Validation workflow an opportunity to cancel the process if the Request properties violate any custom business rules.
Workflows event handlers at the Completion Phase are registered at sequence 1048576(1024*1024). Explicitly registering the workflow at this Execution Order ensures that the Completion Phase workflow runs last after all other registered handlers. In the Completion Phase of the event, the args.Response will be populated with the outcome/output of the business process. The process cannot be canceled at this point, but the output could be used to post updates to other entities or integrated systems.
Example Workflow
Student Account Transaction Service <> Post Account Transaction Payment Event
We called this service method from a Forms Builder sequence that enables users to make payment online.
Validation Phase
-
When creating a workflow based on this event, select Validation Phase for executing the workflow.
-
(Optional) Insert a LogLine activity to mark the beginning of the Validation Phase.
-
Check if the TransactionAmount value is greater than a rule that the institution has for a certain transaction code (e.g., "Books", maximum charge amount is $25.00).
Use an If activity using Condition = args.Request.TransactionAmount > 25
-
If the TransactionAmount fails the rule, set a Validation Message using a CreateValidationItem activity.
-
Insert an Assign activity and specify args.CancelPipelineExecution = True.
-
Publish the workflow.
-
Since the workflow now runs before anything is posted to the database, if the rule fails and the pipeline is canceled, nothing will be posted to the database, and the Validation Message will be returned.
Completion Phase
-
When creating a workflow based on this event, select Completion Phase for executing the workflow.
-
(Optional) Insert a LogLine activity to mark the beginning of the Completion Phase.
-
Before adding your Completion Phase activities, make sure the service method was successful.
This example checks whether the CreateValidationItem activity returned errors using Condition = Not args.Response.ValidationMessages.HasErrors
-
If no errors are found, add your Completion Phase activities. This example sends an email message to confirm receipt of the payment.
-
Publish the workflow.
-
The workflow runs after the TransactionAmount passed the max. amount rule and the payment is posted to the database.
When a workflow with Event Phase is published, the selected Event Phase value is visible (but not editable) in the "Publish New Workflow Definition Version" window.
Workflows Based on Entities
All events for workflows based on entities will run during the Execution Phase. The default value of "Execution" phase is stored to the workflow and is not editable. The Saving, Saved, Deleting, Deleted, Constructed events continue to execute with Execution Order of 100. This ensures backward compatibility and reduces the complexity of designing workflows for CRUD events. The services for CRUD operations already provide a way to cancel workflow execution using the Saving/Deleting events.
Event phases cannot be selected for entity-based CRUD events, such as Constructed, Deleted, Deleting, Saved, and Saving events.
Event Phase Filter
When opening a workflow from the server, you can filter workflows by Event Phase.
You can edit the filter to narrow the search results.