How to recursivly apply an automation chain to a document and to its children (and the children of its children and...) ?

Hi, I want to modify a property of a document and of all its descendants.

I have builded an automation chain (“myChain) to make it recursively. This chain is called by an user action.

It does work only for a document without child…

Here is the chain :

Fetch > Context Document(s)

Document > Update Property -value : myValue -xpath : mySchema:myProperty -saved : checked

Document > Get Children

Execution Context > Set Context Variable From Input -name : myList

Execution Flow > Run For Each -id : myChain -list : myList -isolate : checked -item : item

Can somebody help me ?

0 votes

1 answers

2007 views

ANSWER

Here is the error message I obtain :

No type adapter found for input: class org.nuxeo.ecm.core.api.impl.DocumentModelListImpl and output interface org.nuxeo.ecm.core.api.DocumentModel > Context.FetchDocument:run

04/02/2014



To get all the documents in a container (and sub-sub-sub-documents), you can use the Query operation to ftech all documents whose path starts with the path of the current folder:

Fetch > Query
    query: SELECT * FROM Document WHERE dcm:path STARTSWITH '@{Document.path}'
    language: NXQL

Then, you have a list of documents:

  • If you want to just update some fields, you can directly call Document > Update propertty or Document > Update Properties. The operation will be applyed for each document in the list
  • If you want to run a chain, use Execution Flow > Run Document Chain

So, your chain could be…

Fetch > Context Document
Document > Update Property
    value : myValue
    xpath : mySchema:myProperty
    saved : checked
Fetch > Query
    query: SELECT * FROM Document WHERE dcm:path STARTSWITH '@{Document.path}'
    language: NXQL
Document > Update Property
    value : myValue
    xpath : mySchema:myProperty
    saved : checked

… where all documents will have the “myValue” value in the mySchema:myProperty field.

Or you can use a subchain…

Fetch > Context Document
Document > Update Property
    value : myValue
    xpath : mySchema:myProperty
    saved : checked
Fetch > Query
    query: SELECT * FROM Document WHERE dcm:path STARTSWITH '@{Document.path}'
    language: NXQL
Execution Flow > Run Document Chain
    id: TheSubChain
    isolate: (depends on your needs)
    parameters: (none)

…with TheSubChain doing “something”. Here, I am just logging an information:

Fetch > Context Document
Notification > Log
    level: warn
    message: Current doc is doc id @{Document.id}, path: @{Document.path}

IMPORTANT

The queryhere gets all and every Nuxeo document, which includes containers (Folder, typically), deleted (in the trash), hidden, etc. So, maybe you will want to tune the query. For example, to ignore Folder and usually hidden documents:

SELECT * FROM Document WHERE dcm:path STARTSWITH '@{Document.path}' AND ecm:mixinType != 'HiddenInNavigation' AND ecm:isCheckedInVersion = 0 AND ecm:currentLifeCycleState != 'deleted' AND ecm:primaryType != 'Folder'

Thibaud

0 votes



Thank you very much !

Everything is good now !

04/08/2014