04-14-2023 02:50 AM
Hi,
I made a script in javascript saved in Alfresco Share in the repository.
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.
The code of this script:
function control_block(folder_to_control){ if (folder_to_control && folder_to_control.isContainer) { var children = folder_to_control.children; for (var i = 0; i < 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; }
function main(doc) { control_block(doc); } main(document);
Here are the rules of a folder in the repository:
- when an object enter the folder
- Execute the script
The problem is that in the logs it goes directly in the else block and says that the folder is empty:
2023-04-14 10:54:27,957 DEBUG [repo.jscript.ScriptLogger] [http-nio-8080-exec-1] ERROR: folder to iterate don't exists
I tried several other options like:
function control_block(folder_to_control){ var folder = search.findNode(folder_to_control); ...
But with the same results. I also tried to use directly the document variable like:
function control_block(){ if (document && document.isContainer) { var children = document.children; for (var i = 0; i < children.length; i++) { var child = children[i]; if (child.isDocument) { logger.log(child.name); } ...
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?
Config:
Alfresco 7.2
Best regards.
04-18-2023 12:33 AM
Just change your line
main(document);
to
main(document.parent);
The rule "document" is the one that was created in the folder.
Explore our Alfresco products with the links below. Use labels to filter content by product module.