<?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 Re: Script triggered by rule can't iterate over folder in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/script-triggered-by-rule-can-t-iterate-over-folder/m-p/146428#M38778</link>
    <description>&lt;P&gt;Just change your line&lt;/P&gt;
&lt;PRE&gt;main(document);&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;main(document.parent);&lt;/PRE&gt;
&lt;P&gt;The rule "document" is the one that was created in the folder.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Apr 2023 07:33:15 GMT</pubDate>
    <dc:creator>angelborroy</dc:creator>
    <dc:date>2023-04-18T07:33:15Z</dc:date>
    <item>
      <title>Script triggered by rule can't iterate over folder</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/script-triggered-by-rule-can-t-iterate-over-folder/m-p/146427#M38777</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I made a script in javascript saved in Alfresco Share in the repository.&lt;/P&gt;&lt;P&gt;The goal of this script is to iterate over the folder (linked to rule of triggering this script) and to log all the documents in this folder.&lt;/P&gt;&lt;P&gt;The code of this script:&lt;/P&gt;&lt;PRE&gt;function control_block(folder_to_control){
    if (folder_to_control &amp;amp;&amp;amp; folder_to_control.isContainer) {
        var children = folder_to_control.children;
        for (var i = 0; i &amp;lt; children.length; i++) {
            var child = children[i];
            if (child.isDocument) {
                logger.log(child.name);
            }
        }
    }
	else {
		logger.log("ERROR: folder to iterate don't exists");
	}
	return null;
}&lt;BR /&gt;
function main(doc) {
	control_block(doc);
}

main(document);&lt;/PRE&gt;&lt;P&gt;Here are the rules of a folder in the repository:&lt;BR /&gt;- when an object enter the folder&lt;BR /&gt;- Execute the script&lt;/P&gt;&lt;P&gt;The problem is that in the logs it goes directly in the else block and says that the folder is empty:&lt;BR /&gt;2023-04-14 10:54:27,957 DEBUG [repo.jscript.ScriptLogger] [http-nio-8080-exec-1] ERROR: folder to iterate don't exists&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried several other options like:&lt;/P&gt;&lt;PRE&gt;function control_block(folder_to_control){
	var folder = search.findNode(folder_to_control);
	...&lt;/PRE&gt;&lt;P&gt;But with the same results. I also tried to use directly the document variable like:&lt;/P&gt;&lt;PRE&gt;function control_block(){
    if (document &amp;amp;&amp;amp; document.isContainer) {
        var children = document.children;
        for (var i = 0; i &amp;lt; children.length; i++) {
            var child = children[i];
            if (child.isDocument) {
                logger.log(child.name);
            }
	...&lt;/PRE&gt;&lt;P&gt;What is my error in all this? It seems to me that the document variable refers to the folder that is linked to the rule right?&lt;/P&gt;&lt;P&gt;Config:&lt;BR /&gt;Alfresco 7.2&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 09:50:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/script-triggered-by-rule-can-t-iterate-over-folder/m-p/146427#M38777</guid>
      <dc:creator>Romanesco</dc:creator>
      <dc:date>2023-04-14T09:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: Script triggered by rule can't iterate over folder</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/script-triggered-by-rule-can-t-iterate-over-folder/m-p/146428#M38778</link>
      <description>&lt;P&gt;Just change your line&lt;/P&gt;
&lt;PRE&gt;main(document);&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;main(document.parent);&lt;/PRE&gt;
&lt;P&gt;The rule "document" is the one that was created in the folder.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 07:33:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/script-triggered-by-rule-can-t-iterate-over-folder/m-p/146428#M38778</guid>
      <dc:creator>angelborroy</dc:creator>
      <dc:date>2023-04-18T07:33:15Z</dc:date>
    </item>
  </channel>
</rss>

