cancel
Showing results for 
Search instead for 
Did you mean: 

Weird folder rule behavior

augustodelucena
Champ on-the-rise
Champ on-the-rise
I have a pre-assigned folder structure (SubfolderA, SubfolderB, SubfolderC) at "Data Dictionary/Space Templates/hr-year".

I need to write a javascript rule that checks if a specific folder name already exists and if its true, move the document accordingly or create a folder (a node copy from the pre-assigned folder structure above) and move the document.

I use the code below to determine the noderef of my destination folders and move it

var docyear = "Year " + document.properties["co1:year"];
var destNode1 = document.parent;
var destNode2 = space.childByNamePath(docyear);
var SourceNode = companyhome.childByNamePath("Data Dictionary/Space Templates/hr-year"); // container with pre-designed folder structure
if (destNode2 === null || destNode2.length === 0)
    {  
    //creates folder and moves document
    var newNode = SourceNode.copy(destNode1, true);
    newNode.name = docyear;
    document.move(newNode);
    document.save();
    }  
else {
        //moves document to already present container  
        document.move(destNode2);
        document.save();
    }
}

As I understand when the document enters the folder where the rule resides, it was supposed to run and should give me the following structure
<blockcode>
|–parentfolder
         |—-Year 2015
                  |—–SubFolderA 
                  |—–SubFolderB
                  |—–SubFolderC
</blockcode>
However, the result I'm getting is this folder structure
<blockcode>
|–parentfolder
         |——-Year 'null'
                      |——SubfolderA
                      |——SubfolderB
                      |——SubfolderC
                      |——Year 2015
                                 |——SubfolderA
                                 |——SubfolderB
                                 |——SubfolderC
</blockcode>
Can anybody help me to sort this out or to find a workaround?

PS: The rules is not inherited.
4 REPLIES 4

rjohnson
Star Contributor
Star Contributor
What triggers the rule & do you include sub folders?

Content that is moved or enters the folder
The subfolder option is not flagged.

Regards,

rjohnson
Star Contributor
Star Contributor
First you need newNode.save() after setting the name.

Second, the rule is triggered by something arriving in the parentFolder (presumably the document Library). So Document A arrives & it goes off & tries to create the folder structure. In creating the folder structure SourceNode.copy(destNode1, true) creates a folder structure in the folder that has the rule on it so the rule triggers again.

Try adding to your rule trigger "document type is not a folder" or "document tyoe is cm:content". That may solve your issue.



augustodelucena
Champ on-the-rise
Champ on-the-rise
Thanks Bob!

I will give it a try, I hope that works!