cancel
Showing results for 
Search instead for 
Did you mean: 

javascript iterate object in start node

patrickvanhoof
Confirmed Champ
Confirmed Champ

Hi all,

I use following javascript (only snippet of the code):


function main() {

   if (document.isContainer && document.name == "Gescande dossiers")
    {

        processNode(document);
    }
}

main();

I have a rule defined on the document library that executes that script, when folder "Gescande dossiers" is found it should continue. But it seems this is only iterating documents in the current folder, not the subfolders.

Function main() does not iterate on all object in the folder?

Thanks,

Patrick

6 REPLIES 6

mehe
Elite Collaborator
Elite Collaborator

Why should main() iterate over all objects in the folder? There is no line of code that implies a recursion or loop.

Because that's the implemenattion of main(), as far as I know. I used it that way several times.

mehe
Elite Collaborator
Elite Collaborator

sorry, but no - "main" ist just a name, could also be "patrick". No logic is implied if you use main.

Your code could also be

 if (document.isContainer && document.name == "Gescande dossiers")
    {

        processNode(document);
    }
}

and would do the same. Your rule, as far as the code says, does the following:

- document is the node that has triggered the rule

- check if triggering node is a container (folder) and has the name "Gescande dossiers"

- if yes, call processNode with the node "Gescande dossiers"

processNode would have to do the job to iterate over the children of "Gescande dossiers" (=document).

Maybe you want something different - if your rule applied to subfolders too? Then maybe you don't want to check if "document.name" is "Gescande dossiers" but document.parent.name ... ?

Sorry, but I do not agree, cause when I put logging on for 'document.name' it gives me a record for each file, but not for the folders...

mehe
Elite Collaborator
Elite Collaborator

...if you are agree or not. It isn't working like you expect. To analyze what is going wrong, you would have to provide your rule definition and what you want to achieve.

If you define an incoming rule (onCreate) without any filtering, then it will be triggered by any object - file, folder or what else - that is created or moved to the corresponding folder (in which the rule is anchored). 

Martin,

Sorry, you are right. It was the rule that was not defined correctly... I checked it and there was indeed a condition that was not defined correctly. It works now after correction.

Thanks.

Patrick