Workflow Post Step Logic
With Workflow Post Step Logic it is possible to run a custom logic after a particular step in a workflow was executed. This allows you to use the result of that step in the logic. For example, 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.
This functionality is intended only for modifying the workflow logic (e.g., add approval/watcher steps, implement custom workflow notifications). It is not designed to handle complex logics outside of the workflow scope.
To create a Workflow Post Step Logic:
Go to Administration > Logics > Workflow Logics > Workflow Post Step Logics.
Click the Add Logic button to set up a new Workflow Post Step Logic. Its uniqueName must be different from the  Workflow Logic name.
In the logic you can use options available for the workflow logic or calculation logic.
In addition, you can use here two specific methods (belonging to the currentWorkflow variable) which insert additional steps:.insertApprovalStep(String stepName)
.insertWatcherStep(String stepName)
You can also work with theÂ
approvable
 variable which represents the object for which the workflow is used. (In case of a workflow used for a Quote, there is also the specific objectÂquote
, for Agreement/Promotion workflow there is theÂcontract
 object etc. but these specific objects point to the same object asÂapprovable
. TheÂapprovable
 object is useful if you want to make your Post Step Logic universal.)Save the Workflow Post Step Logic.
Go back to your workflow logic and use one of the following methods:
.withPostStepLogic(String postStepLogicUniqueName)
– Runs the given post step logic after the step in which you have used this method. This has a higher priority over the Default Post Approval Step Logic..withDefaultPostApprovalStepLogic(String postStepLogicUniqueName)
– Runs the given post step logic after every approval step in the workflow.
 If you specify the Post Step Logic in a step but keep it empty (
.withPostStepLogic("")
), it disables Post Step Logic for the given step.After you save your workflow logic, the presence of the Workflow Post Step Logic is visible in the Workflow window – in the Post Step Logic Name column of the corresponding step.
Once the step is executed (i.e., becomes Approved, Denied or Withdrawn), the custom logic code is run. If the run was successful, the cell becomes green; if it failed, it is red and you can find the error in the log.
 It is also possible to run a Workflow Post Step Logic even when there is no workflow defined or no approval steps are generated. See the sections below.
See also the section Approval Workflow Post Step Logic in the Developer Knowledge Base.
Examples
This workflow logic defines that after every approval step the Post Step Logic "defaultPostLogic" will be executed – except for the first approval step in which running of a Post Step Logic is disabled.
workflow
.withDefaultPostApprovalStepLogic("defaultPostLogic")
workflow
.addApprovalStep("DefaultApproval")
.withApprovers("user1")
.withPostStepLogic("")
.setReason("Standard approval")
workflow
.addApprovalStep("ExtraApproval")
.withApprovers("user2")
.setReason("Additional approval")
This Post Step Logic example shows how to insert another approval step "postAdded" when the step (after which this Post Step Logic was executed) was approved.
if (workflowHistory.activeStep.approved) {
currentWorkflow.insertApprovalStep("postAdded").withApprovers("user")
}
This Post Step Logic checks whether the whole workflow got approved or not.
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()}"])
}
This Post Step Logic example shows how to insert a new approval step and disable executing Post Step Logic in the step being inserted.Â
Running Post Step Logic with No Workflow
It is possible to run a Workflow Post Step Logic even when there is no workflow defined. This can be useful when you want to take advantage of the logic context built around the workflow, yet you do not need the approval workflow.
The prerequisite is that you define a post step logic in Advanced Configuration Options. As a key in JSON, you need to use the same names of entities as in the workflow email, e.g., pricegriditem
for a (Matrix) Price Grid Item; as a value in JSON use the name of the post step logic that will be run.
Property name:
Value:
Then you need a logic with a single element containing this Groovy script (id
and priceGridId
must be supplied):
For this use case we do not provide any variables for the Groovy sandbox due to performance reasons. The item is available in api.currentItem()
, and you need to be careful not to execute the full to-json conversion; instead you should pick only the fields you need (otherwise the performance may suffer).
Running Post Step Logic with No Approval Steps Generated
If you need to run a post step logic even if the workflow logic is executed but it does not generate any steps, there is a new method on workflowDTO withRunDefaultPostApprovalStepLogicOnEmptyWorkflow(boolean)
. When you call it with true, the logic specified in withDefaultPostApprovalStepLogic(String)
will be also run in this case.
Any code in myDefaultPostStepLogic
will be run too.
Found an issue in documentation? Write to us.
Â
Pricefx version 13.1