Condition in an automation chain

Hi, How can I use some sort of conditional statement in the automation chain? I want to create a document under the private workspace of an user only if it wasn't created before.

Thank you!

1 votes

1 answers



Assuming you are doing that in Nuxeo-Studio:

Start by creating 2 operations:

  1. The first of type: “Document > Create”, let's call it CREATE_MY_DOC.

      You could supply here a document path as a parameter of your expected/existing document.
  2. The second of type: “User Interface > Add Info Message”, let's call it NOTIFY_DOCUMENT_EXISTS.

      This is just an example, you could use a void operation instead.

Then create your “logic” operation of type: “Execution Flow > Run Operation”

Give this operation an ID of the following form: (condition?op1:op2) where if the “condition” is true, then “op1” is executed, otherwise “op2”

In the condition statement you can check if your document exists, for instance using NXQL:

@{(Session.query("SELECT * FROM Document WHERE ecm:path='MY_PATH").size()==0?"CREATE_MY_DOC":"NOTIFY_DOCUMENT_EXISTS")}

This should launch the appropriate operation creating the document if, and only if, it does not yet exist.

3 votes

Using "Execution Flow > Run Operation" is the key. But to avoid limits of using ternary operator which enables you to choose among only two different behaviors, you can actually "compute" the name of the operation chain to execute in a previous "Run Script" operation, storing the result in a context variable and referencing it in the "ID" parameter of Run Operation.