<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Running a chain for each Document in a DocumentList (Have casting issues) in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/running-a-chain-for-each-document-in-a-documentlist-have-casting/m-p/318651#M5652</link>
    <description>&lt;P&gt;Hi! I'm working on an automation chain in studio, and I'm running into an issue on trying to recursively apply a RunDocumentOperation operation to each document returned from a query.&lt;/P&gt;
&lt;P&gt;The general structure is I have this contextual user action, when pressed, it will query documents that were modified within a set date range. For each of these modified documents, I'd like to run a specific automation chain (the same one for each document). So my starter chain looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Automation Chain Name: ac_find_modified

- Repository.Query:
    query: "SELECT * FROM Document WHERE dc:modified BETWEEN DATE '2018-10-10' AND DATE '2018-10-15'"
    language: NXQL
    sortOrder: ASC
- RunDocumentOperation:
    id: my_test_chain
    isolate: "false"
    rollbackGlobalOnError: "false"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What happens is that the query operation returns a DocumentList type, which I believed was okay to perform the RunDocumentOperation (according to the solution from this: &lt;A href="https://answers.nuxeo.com/general/q/ae6a0c4c46f24bb3a317a075f056d95f/How-to-recursivly-apply-an-automation-chain-to-a-document-and-to-its-children-and-the-children-of-its-children-and" target="test_blank"&gt;https://answers.nuxeo.com/general/q/ae6a0c4c46f24bb3a317a075f056d95f/How-to-recursivly-apply-an-automation-chain-to-a-document-and-to-its-children-and-the-children-of-its-children-and&lt;/A&gt; )&lt;/P&gt;
&lt;P&gt;However what I observed is after the query search, it would proceed to run the first document of the results through the "my_test_chain" automation chain and finish. However after finishing, it errors with the following&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;****** end sub chain ******


    at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:238)
    at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:97)
    at org.nuxeo.ecm.automation.jsf.OperationActionBean.runOperation(OperationActionBean.java:94)
    at org.nuxeo.ecm.automation.jsf.OperationActionBean.doOperation(OperationActionBean.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
.....
.....
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.nuxeo.ecm.automation.OperationException: Failed to invoke operation RunDocumentOperation with aliases [Context.RunDocumentOperation]
    at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:189)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:130)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:116)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:133)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:116)
    at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:214)
    ... 105 more
Caused by: java.lang.ClassCastException: org.nuxeo.ecm.core.api.impl.DocumentModelListImpl cannot be cast to org.nuxeo.ecm.core.api.DocumentModel
    at org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain.run(RunDocumentChain.java:95)
    at org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain.run(RunDocumentChain.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:171)
    at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:177)
    ... 110 more
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it helps, the header of the automation chain traceback in the logs was:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;****** chain ******
Name: ac_find_modified
Exception: OperationException
Caught error: Failed to invoke operation RunDocumentOperation with aliases [Context.RunDocumentOperation]
Caused by: java.lang.ClassCastException: org.nuxeo.ecm.core.api.impl.DocumentModelListImpl cannot be cast to org.nuxeo.ecm.core.api.DocumentModel
****** Hierarchy calls ******
    org.nuxeo.ecm.automation.core.operations.services.query.DocumentPaginatedQuery
        org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I just wanted to make sure this is the procedure to perform if you simply want to apply one automation chain to every document returned from a query. I'm kinda confused on why it actually processes the first element, but procedures to error after the first run?  Another note is that the "my_test_chain" does start with Context.FetchDocument , which I was wondering maybe that is responsible since the error complains about casting a DocumentList to a Document and it is expecting a Document. However I read the description and said:&lt;/P&gt;
&lt;P&gt;"Fetch the input of the context as a document or list of documents. The document will become the input for the next operation."&lt;/P&gt;
&lt;P&gt;So it sounds like it should accept a list as well. So is it actually the RunDocumentOperation from my "ac_find_modified" chain?&lt;/P&gt;</description>
    <pubDate>Thu, 01 Nov 2018 21:00:26 GMT</pubDate>
    <dc:creator>Peter_Tucker</dc:creator>
    <dc:date>2018-11-01T21:00:26Z</dc:date>
    <item>
      <title>Running a chain for each Document in a DocumentList (Have casting issues)</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/running-a-chain-for-each-document-in-a-documentlist-have-casting/m-p/318651#M5652</link>
      <description>&lt;P&gt;Hi! I'm working on an automation chain in studio, and I'm running into an issue on trying to recursively apply a RunDocumentOperation operation to each document returned from a query.&lt;/P&gt;
&lt;P&gt;The general structure is I have this contextual user action, when pressed, it will query documents that were modified within a set date range. For each of these modified documents, I'd like to run a specific automation chain (the same one for each document). So my starter chain looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Automation Chain Name: ac_find_modified

- Repository.Query:
    query: "SELECT * FROM Document WHERE dc:modified BETWEEN DATE '2018-10-10' AND DATE '2018-10-15'"
    language: NXQL
    sortOrder: ASC
- RunDocumentOperation:
    id: my_test_chain
    isolate: "false"
    rollbackGlobalOnError: "false"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What happens is that the query operation returns a DocumentList type, which I believed was okay to perform the RunDocumentOperation (according to the solution from this: &lt;A href="https://answers.nuxeo.com/general/q/ae6a0c4c46f24bb3a317a075f056d95f/How-to-recursivly-apply-an-automation-chain-to-a-document-and-to-its-children-and-the-children-of-its-children-and" target="test_blank"&gt;https://answers.nuxeo.com/general/q/ae6a0c4c46f24bb3a317a075f056d95f/How-to-recursivly-apply-an-automation-chain-to-a-document-and-to-its-children-and-the-children-of-its-children-and&lt;/A&gt; )&lt;/P&gt;
&lt;P&gt;However what I observed is after the query search, it would proceed to run the first document of the results through the "my_test_chain" automation chain and finish. However after finishing, it errors with the following&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;****** end sub chain ******


    at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:238)
    at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:97)
    at org.nuxeo.ecm.automation.jsf.OperationActionBean.runOperation(OperationActionBean.java:94)
    at org.nuxeo.ecm.automation.jsf.OperationActionBean.doOperation(OperationActionBean.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
.....
.....
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.nuxeo.ecm.automation.OperationException: Failed to invoke operation RunDocumentOperation with aliases [Context.RunDocumentOperation]
    at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:189)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:130)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:116)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:133)
    at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:116)
    at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:214)
    ... 105 more
Caused by: java.lang.ClassCastException: org.nuxeo.ecm.core.api.impl.DocumentModelListImpl cannot be cast to org.nuxeo.ecm.core.api.DocumentModel
    at org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain.run(RunDocumentChain.java:95)
    at org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain.run(RunDocumentChain.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:171)
    at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:177)
    ... 110 more
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it helps, the header of the automation chain traceback in the logs was:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;****** chain ******
Name: ac_find_modified
Exception: OperationException
Caught error: Failed to invoke operation RunDocumentOperation with aliases [Context.RunDocumentOperation]
Caused by: java.lang.ClassCastException: org.nuxeo.ecm.core.api.impl.DocumentModelListImpl cannot be cast to org.nuxeo.ecm.core.api.DocumentModel
****** Hierarchy calls ******
    org.nuxeo.ecm.automation.core.operations.services.query.DocumentPaginatedQuery
        org.nuxeo.ecm.automation.core.operations.execution.RunDocumentChain

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I just wanted to make sure this is the procedure to perform if you simply want to apply one automation chain to every document returned from a query. I'm kinda confused on why it actually processes the first element, but procedures to error after the first run?  Another note is that the "my_test_chain" does start with Context.FetchDocument , which I was wondering maybe that is responsible since the error complains about casting a DocumentList to a Document and it is expecting a Document. However I read the description and said:&lt;/P&gt;
&lt;P&gt;"Fetch the input of the context as a document or list of documents. The document will become the input for the next operation."&lt;/P&gt;
&lt;P&gt;So it sounds like it should accept a list as well. So is it actually the RunDocumentOperation from my "ac_find_modified" chain?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 21:00:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/running-a-chain-for-each-document-in-a-documentlist-have-casting/m-p/318651#M5652</guid>
      <dc:creator>Peter_Tucker</dc:creator>
      <dc:date>2018-11-01T21:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Running a chain for each Document in a DocumentList (Have casting issues)</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/running-a-chain-for-each-document-in-a-documentlist-have-casting/m-p/318652#M5653</link>
      <description>&lt;P&gt;Generally using an automation script is more appropriate for iterating through lists of documents.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 22:37:00 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/running-a-chain-for-each-document-in-a-documentlist-have-casting/m-p/318652#M5653</guid>
      <dc:creator>Jackie_A</dc:creator>
      <dc:date>2018-11-28T22:37:00Z</dc:date>
    </item>
  </channel>
</rss>

