AnsweredAssumed Answered

Weird folder rule behavior

Question asked by augustodelucena on Nov 9, 2015
Latest reply on Nov 11, 2015 by augustodelucena
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.

Outcomes