javascript iterate object in start node

cancel
Showing results for 
Search instead for 
Did you mean: 
patrickvanhoof
Customer

javascript iterate object in start node

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
mehe
Senior Member II

Re: javascript iterate object in start node

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

patrickvanhoof
Customer

Re: javascript iterate object in start node

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

mehe
Senior Member II

Re: javascript iterate object in start node

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 ... ?

patrickvanhoof
Customer

Re: javascript iterate object in start node

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
Senior Member II

Re: javascript iterate object in start node

...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). 

patrickvanhoof
Customer

Re: javascript iterate object in start node

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