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.
Just change your line
main(document);
to
main(document.parent);
The rule "document" is the one that was created in the folder.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.