Platform Explorer / Nuxeo Platform 5.6

Operation Context.SetInputAsVar

Set Context Variable From Input

Description

Set a context variable that points to the current input object. You must give a name for the variable. This operation works on any input type and return back the input as the output.

This operation is useful when you need to reinject later on a document in the pipe of the chain. Indeed, an operation accepts a document (or a blob) and produces a document. In many operations it is the same document, but in some other operations, the document that goes out of the operation is different than the one that went in. Yet, in that case, it happens that you want to work again on the initial document. For that reason, you need a mean to "buffer" the initial document, to be able to easily fetch it again later on. Let’s take the sample use case where we want to create a substructure in the User workspace using an Event Handler that calls an automation chain on a "Document Created" event, if the path of the document starts with /default-domain/UserWorkspaces/. Goal is to create folders "humanResources", "myBookmarks", and "myPictures" just below it.

  • userWorkspace
    • humanResources
    • MyBookmarks
    • My Picture

We use the Document > Create operation for this, which accepts the parent document and produces the created document. If we want to use the Document > Create operation twice or three times in a row, we need between each of them to re-inject the parent folder, otherwise, the result will be :

  • userWorkspace
    • humanResources
      • MyBookmarks
        • My Pictures

Which is not what we want.That’s where the operations "Execution Context > Set Context Variable From Input" and "Execution Context > Restore Document Input" are useful. The chain will look like the following:

  1. Fetch > Context Document
  2. Execution Context > Set Context Variable From Input
    • name= userWorkspace
  3. Document > Create
    • Type= Folder
    • name= humanResources
    • properties= dc:title= Human Resources
  4. Execution Context > Restore Document Input
    • name= userWorkspace
  5. Document > Create
    • Type= Folder
    • name= myBookmarks
    • properties= dc:title= My Bookmarks
  6. Execution Context > Restore Document Input
    • name= userWorkspace
  7. Document > Create
    • Type= Folder
    • name= MyPictures
    • properties= dc:title= My Pictures

You can also find another example here: Implement document validation chain

Operation id Context.SetInputAsVar
Category Execution Context
Label Set Context Variable From Input
Requires
Since

Parameters

Name Description Type Required Default value
name string yes  

Signature

Inputs void
Outputs void

Implementation information

Implementation class org.nuxeo.ecm.automation.core.operations.SetInputAsVar
Contributing component BuiltIn

JSON definition

{
  "id" : "Context.SetInputAsVar",
  "label" : "Set Context Variable From Input",
  "category" : "Execution Context",
  "requires" : null,
  "description" : "Set a context variable that points to the current input object. You must give a name for the variable. This operation works on any input type and return back the input as the output.",
  "url" : "Context.SetInputAsVar",
  "signature" : [ "void", "void" ],
  "params" : [ {
    "name" : "name",
    "description" : "",
    "type" : "string",
    "required" : true,
    "widget" : null,
    "order" : 0,
    "values" : [ ]
  } ]
}