Automation

How to Write Reusable Automation Chains

In your project, you might have some automation chains that all look the same, with the same structure, meaning the same operations in the same order, and the only difference is that the parameters values sent to the composing operations are not the same. This usually means you can factorize your implementation using parameterized chains.

Let's take an example: You want to change the life cycle of a document, and log at the same time the company of the user who changed the document life cycle state in the audit. Genuinely, 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 life cycle 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 life cycle transitions.

 


4 months ago manonlumeau Relocated assets to fit new URL structure for 710 - fix
5 years ago Solen Guitter 14 | ix broken excerpt includ
5 years ago Solen Guitter 13
5 years ago Solen Guitter 12
5 years ago Solen Guitter 11 | Fix formatting in ChangeCaseStatus chain, update links
5 years ago Solen Guitter 10 | Added related topics
5 years ago Thibaud Arguillere 9
5 years ago Alain Escaffre 8
5 years ago Alain Escaffre 6
5 years ago Alain Escaffre 7
5 years ago Alain Escaffre 5
5 years ago Alain Escaffre 4
5 years ago Alain Escaffre 3
5 years ago Alain Escaffre 2
5 years ago Alain Escaffre 1
History: Created by Alain Escaffre

We'd love to hear your thoughts!

All fields required