Nuxeo Server

How to Write Reusable Automation Chains

Updated: September 22, 2017 Page Information Edit on GitHub

You might have some automation chains in your project that all have a similar structure, meaning the same operations in the same order, the only difference being that the parameter values sent to the composing operations are different. Usually in this case, you can factorize your implementation using parameterized chains.

Let's take an example: You want to change the lifecycle of a document, while logging the company of the user who changed the document lifecycle state in the audit. If you want a chain that validates a document, you would write the following chain:

- Context.FetchDocument
- Document.SetLifeCycle:
    value: approve
- Audit.Log:
    event: test
    category: Automation
    comment: "@{CurrentUser.company}"

If you want to do it for each lifecycle changes (making it obsolete, or draft, ...), you would have to write several chains calling the Document.SetLifeCycle and Audit.Log operations.

Or your can use a parameterized chain:

  1. Create a chain called "ChangeCaseStatus".

    params:
    - transitionName:
        type: string
    - userPropertyToLog:
        type: string
    operations:
    - Context.FetchDocument
    - Document.SetLifeCycle:
        value: "@{ChainParameters['transitionName']}"
    - Audit.Log:
        event: test
        category: Automation
        comment: "@{CurrentUser.getProperty(ChainParameters['userPropertyToLog'])}"
    

    To declare the parameters of a chain, you can use the Chain Parameters tab of the Automation Chain feature in Nuxeo Studio. To reference a parameter's value inside the chain:

    @{ChainParameters['parameterName']}

  2. Create a second chain that references the first chain with a Run Chain operation, using the parameters field. This second chain is used to approve document.

    - Context.RunOperation:
        id: ChangeCaseStatus
        isolate: 'false'
        parameters:
          userPropertyToLog: company
          transitionName: approve
    

    You can then leverage this chain with a user action.

  3. Repeat step 2 to create as many chains as you need to follow the different lifecycle transitions.


2 days ago Solen Guitter Don't show excerpt 'upgrade-9.2-drop-change-token' and add comment
3 years ago Solen Guitter 14 | ix broken excerpt includ
3 years ago Solen Guitter 13
3 years ago Solen Guitter 12
3 years ago Solen Guitter 11 | Fix formatting in ChangeCaseStatus chain, update links
3 years ago Solen Guitter 10 | Added related topics
3 years ago Thibaud Arguillere 9
3 years ago Alain Escaffre 8
3 years ago Alain Escaffre 6
3 years ago Alain Escaffre 7
3 years ago Alain Escaffre 5
3 years ago Alain Escaffre 4
3 years ago Alain Escaffre 3
3 years ago Alain Escaffre 2
3 years ago Alain Escaffre 1
History: Created by Alain Escaffre