Workflow Steps guide
Overview¶
Workflow configuration is separated into named workflow steps. Routes define which step will be executed when document match criteria are met.
Workflow steps are maintained using the Portal. Read the Workflow user interface guide for more information about the interface use.
Workflow steps are defined using an XML model. The XML elements and attributes are a mix of mandatory and conditional values that define the behaviour of the workflow service.
Workflow step invocation¶
The service is typically called via the Routes service as the result of a p6route
route evaluation.
Possible headers values are:
Header value | Description |
---|---|
step |
The workflow step’s id (required) |
flowName |
Fixed value for flow name. Use %UUID% to auto generated uuid formatted flow name. |
status |
The initial status of the message (required) |
script |
The name of the step template script |
pipelineVar |
The input pipeline content to script |
Here is an example of a workflow step invocation via a route deployment script.
from("seda:wfroute.test") .when(xpath("/TransactionMetaData/TechnicalStatusCode='Pending'")) .setHeader("platform6.request.action").constant("invoke") .setHeader("status").constant("PENDING") .setHeader("step").constant("Dispatch Field Ticket") .setHeader("flowname").constant("%UUID%") .to("p6route://workflowsteps") .otherwise() .throwException(com.amalto.b2box.core.api.B2boxException, "No matching rule found for item!") .end() .routeId("WF_Route.Test")
Note
Item Primary Key component headers are auto generated by the P6route component.
Header value: script
The script
header allows a script to generate the workflow step definition XML.
This is useful when, for example, a message containing a cost centre is received and depending upon the value of this field, different workflow assignees are required.
Using the script header allows a steps XML configuration to be templated.
Script input pipeline
Header’s key | Description |
---|---|
platform6.request.cluster |
The cluster (primary key component) |
platform6.request.concept |
The concept (primary key component) |
platform6.request.ids |
The ids as a comma separated list (primary key component) |
templateStepXml |
The content of the current step XML defined by the step parameter as type text/xml |
Script output pipeline
Header’s key | Description |
---|---|
stepXml |
The new step XML configuration generated by the script (required) |
stepName |
If available, will be used as the name of the new step stored as part of the service configuration |
If the stepName
is not available a new auto-generated service step configuration will be created with the name format: __paramstepname_GUID.
Note
A step XML generated via a script is not stored as a service’s configuration. However, it is stored in the generated work item for the lifetime of this workflow step.
Workflow custom forms¶
It is possible to use custom forms triggered by Workflow.
Workflow step modification
Inside the Action
that is going to call the custom form, add a FormGenerator
element with the name of the custom form.
<Actions> <Action id="review" status="REVIEWED" type="FORM" transformer="AWF_Review"> <Style>icon:fa-check,btn:btn-success</Style> <Label> <EN>Review</EN> <FR>VĂ©rifier</FR> </Label> <FormGenerator>MyCustomForm</FormGenerator> ... </Action> ... </Actions>
The FormGenerator
name must match that of a script in the Scripts service.
Script’s headers
The script should start with the following headers.
import groovy.json.* @B2RequiredEndpointScope(feature = "forms", action = "read") @Field def boolean endpointEnabled
Parameters passed to the script
Four parameters are passed to the script from the pipeline:
pk
: a JSON string containing the primary key of the work item.
{ "dataCluster": "B2BOX", "concept": "AWFWorkItem", "ids": ["64cb15dafd0a11e699620242ac120005"] }
xml
: an XML string with the content of the work item.user
: the user’s email (id).itemLinks
: a JSON Array (string) with the list of Items Links (name, pk and type) of the work item.
[ { "name": "MessageLink", "pk": { "dataCluster": "B2BOX", "concept": "MessageInfo", "ids": ["WFTestForm-2017-02-27 04:32:54 GMT"] }, "type": "" } ]
Two solutions:
-
Directly from the work item XML.
def xml = pipeline.getXml 'xml' def mpk = item.buildPK(xml.itemDataClusterName.text(), xml.itemConceptName.text(), xml.itemIds.text().split('\\.')) def message = item.get(mpk)
-
From the Item Links (the Message is the first link).
def itemLinks = pipeline.get 'itemLinks' def ils = new JsonSlurper().parseText(itemLinks) def mpk = item.buildPK(ils[0].pk.dataCluster, ils[0].pk.concept, ils[0].pk.ids.toArray(new String[ils[0].pk.ids.size()])) def message = item.get(mpk)
Sending the actual form
The form must be developed in JavaScript (or TypeScript) and available in the Scripts service.
The form can be passed a JSON model with data to be displayed in the form.
def model = [ user: 'Jsohn Doe', companySiret: '48432937000049', latestProduct: [ name: 'b2box', url: 'http://www.amalto.com' ] ] pipeline.put 'model', JsonOutput.toJson(model) pipeline.put 'form', scriptResources.getCompiled( 'MyCustomForm' )
Implementing a custom workflow form
To get you started quickly on how to create your first custom workflow form, you can find a demo project in the platform6-custom-workflow-form repository.
It will allow you to generate a JavaScript bundled file which can be simply copy-pasted to any Script of your Platform 6 instance.
Please follow the instructions in the README.md
of the repository to create, test and deploy your form on your instance.