Document.GetChildren: filter out .trashed

Is it possible to have Document.GetChildren not return .trashed files? By default they are included:

    {
      "path": "/test/The Basics.pdf._1547968140071_.trashed",
      "uid": "44cf396c-dbe3-4e21-8886-e0a1d3a76a91",
      "properties": {},
      "title": "The Basics.pdf",
      "type": "File"
    }

The @children operator on the other hand, does not include them by default.

0 votes

1 answers

200 views

ANSWER



Hi Milan,

Is the Document.GetChildren being called in an automation chain? If you are trying to filter out .trashed versions, this can be accomplished via the RunScript operator.

First create a new automation chain that is empty.
In the automation chain, run Document.GetChildren from the FetchedDocument
Set a RunScript operator and use something like this in the script

var childpath = Document.path;  
 if(childpath.split('.').pop()) == 'trashed') {
    Context['isTrash'] = "true";
 }  
 else {
 }  

After this RunScript operator, use a RunOperation operator that checks the variable 'isTrash'. If it's true, then redirect to that empty automation chain so it doesn't do anything with it. However if it's false, then proceed with your expected next operator to process the non-trashed child document.

Hope this helps.

0 votes



thanks! But no, I'm calling this as a regular API call to fetch the folder children.
06/25/2019

I don't think you can do this in a single request. This may not be helpful for your situation, but you could use NXQL search to identify the folder (ecm:path STARTSWITH) and specify that the children are not in the trash (ecm:isTrashed=0) http://localhost:8080/nuxeo/api/v1/search/lang/NXQL/execute?query=SELECT%20*%20FROM%20Document%20WHERE%20ecm:path%20STARTSWITH%20%27/test%27%20AND%20ecm:isTrashed=0
06/25/2019