Workflow, Post Step Logic - Handbook
Samples of usage:
If an approval is handled by a person not belonging to the sales organisation the deal is for, you can trigger automatic adding of an extra approval step.
You want to stop the approval process under some specific conditions.
You want to log aside all approval operations, to build a report of approval process duration.
Send an email notification after specific approval Step execution (e.g., when specific Step was denied).
Flow
Basic Flow
A Workflow Step is executed - it becomes Approved, Denied or Withdrawn.
The Post Step logic (if it is set up to be used for the Step) is executed. During the execution it can:
Read the current workflow situation (and state) and decide based on that information.
Create new Workflow Steps.
Write to tables (via
api.update()
), so you can write various audit information.
It is also possible to run a Workflow Post Step Logic even when there is no workflow defined or no approval steps are generated. For details see Workflow Notes.
Example of Flow with Adding New Workflow Step
There are many possible scenarios regarding the usage of the Post Step logic, here we show one, where the Post Step logics examines the approver of the previous step, and depending on approver’s groups it creates an additional Workflow Step.
A Workflow Step is executed - it becomes Approved, Denied or Withdrawn.
The Post Step logic is executed. Based on the roles of the actual approver, it:
Either adds new Approval Step and the workflow will continue with that new Step.
Or the approval workflow will continue with the Step 2 (which was built by the normal Workflow logic).
Configuration
You can set up a Workflow Post Step Logic to run after a particular step in the workflow has been executed (with the result approved/denied/withdrawn). You can use this step’s result in the Post Step logic to make a decision.
Workflow Logic
Workflow logic builds the workflow Steps, and can add the Post Step logic to any of the Steps. It can either add a default Post Step logic, which will be started after execution of each Step or it can add specific Post Step logic to a particular workflow Step.
Methods of:
WorkflowDTO
withDefaultPostApprovalStepLogic(String postStepLogicUniqueName) - Sets the same Post Step logic for all Steps.
ApprovalStepDTO
withPostStepLogic(String postStepLogicUniqueName) - Sets the Post Step logic for an individual Step.
.withPostStepLogic("") - Disables the Post Step logic for an individual Step.
Workflow logic sample - how to add Post Step logic
workflow.withDefaultPostApprovalStepLogic("DefaultPostLogic") // ❶
workflow.addApprovalStep("DefaultApproval")
.withApprovers("user1")
.withPostStepLogic("") // ❷
.setReason("Standard approval")
workflow.addApprovalStep("ExtraApproval") // ❸
.withApprovers("user2")
.setReason("Additional approval")
❶ Default Post Step logic for all Steps.
❷ Disabling the Post Step logic for this specific step.
❸ This step will use the default Post Step logic, because it does not override and does not disable.
Post Step Logic
Is a logic of type Workflow, nature Post Step.
Post Step logic is executed right after the Approval Step has been executed (i.e., approved / denied / withdrawn).
The Post Step logic has the right to modify data tables, e.g., you can use methods like api.addOrUpdate()
to write various audit logs or statuses to tables (e.g., Company Parameters).
Special Variables (Bindings) Available in Post Step Logic
workflowHistory
Map (with keys "steps", "activeStep"; each Step has e.g., also the key "stepHistory").Samples:
workflowHistory.activeStep.approved
workflowHistory.activeStep.denied
workflowHistory.activeStep.executedByNames[0]
workflowHistory?.steps?.collect{it.approved}
currentWorkflow
Is of type InsertWorkflowStepsDTO.Samples:
currentWorkflow.insertApprovalStep(String stepName)
currentWorkflow.insertWatcherStep(String stepName)
quote | pricegriditem | rebateagreement | contract | dcr | pricelist | rebaterecord
The document being in the approval process.
approvable
Points to the same as Quote, Agreement/Promotion, etc.Could be useful if you needed a universal Post Step logic, regardless of the document type.
api.currentItem() - Reference to the same entity as variable approvable.
Post Step Logic Code Samples
Post Step logic sample - Adding of new Step, when the current Step has been approved
if (workflowHistory.activeStep.approved) {
currentWorkflow.insertApprovalStep("postAdded").withApprovers("user")
}
Post Step logic sample - Check if all of the Approval Steps are already approved
if (workflowHistory.steps.findAll{it.approvalStep}.every{it.approved}) { // ❶
api.addOrUpdate("P", [ // ❷
sku: api.uuid(),
attribute1: "approved ${approvable.getTypedId()}"
]
)
} else {
api.addOrUpdate("P", [
sku: api.uuid(),
attribute1: "notApprovedYet ${approvable.getTypedId()}"
]
)
}
❶ Check if all Steps have been approved.
❷ Store the information about complete approval of the SKU to the attribute of the Product master table.
Post Step logic sample - Insert a new approval step and disable executing the Post Step logic
❶ Inserting new Approval Step.
❷ Disable executing Post Step logic in the step being inserted.
Testing Post Step Logic
Pricefx Studio does not have yet support for Post Step logics, so you must:
Add writing of debugging information to the Log file (e.g.,
api.logInfo()
).Deploy the logic to your partition.
Open the Log (Administration > Logs > Logs) in a separate tab.
Submit the document for approval.
Approve/deny/withdraw the Step (which has the Post Step logic assigned).
This will trigger the Post Step logic of the Step.
Check the Log for your messages.
Error Handling
As this logic is running as a background process, it does not have any UI, where you could see its status.
If the logic ends OK (without any exception), its name in the Workflow window is displayed in GREEN color.
If the logic fails with any exception (either unhandled or raised by the logic), its name in the Workflow window will be RED but the process will continue - i.e., the next Approval Step will be executed.
If you need to stop processing of the workflow, it’s not possible but from such Post Step logic you can add a new Step, which should be approved e.g., by Admin.
References
Documentation
Knowledge Base
Groovy API
Found an issue in documentation? Write to us.