Workflow 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 UI.

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 The step override 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

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 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": ""
    }
]
Recovering the underlying Message (typically a MessageInfo)

Two solutions:

  1. 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)
    
  2. 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' )