Rule file moves subfolders too with original document

cancel
Showing results for 
Search instead for 
Did you mean: 
piyush48
Active Member II

Rule file moves subfolders too with original document

Jump to solution

Hi All,

I am writing rule for moving document created inside folder to a new folder hierarchy created dynamically through cm:created. Now i only want documents created inside folder to be only moved not subfolders which are already there.

Could anyone told what i am doing wrong with code:- 

var createdDate = document.properties["cm:created"];
var scanId = document.properties["live:uniqueDocument"];
var date = new Date(createdDate);
var year = ""+date.getFullYear();
var month = ""+(date.getMonth()+1);
var day = ""+date.getDate();
var hour = ""+date.getHours();
var min = ""+date.getMinutes();
var formattedDate = year+"-"+month+"-"+day;
var calender = [year,formattedDate,day,hour,min];
var parent = document.parent;
for(var i =0; i<calender.length;i++) {
var myfolder = parent.childByNamePath(calender[i]);
if (myfolder === null) {
    myfolder = parent.createFolder(calender[i]);
}
 parent = myfolder;
}
document.move(myfolder);

Thanks and Regards,

Piyush

1 Solution

Accepted Solutions
3 Replies
afaust
Master

Re: Rule file moves subfolders too with original document

Jump to solution

Likely nothing wrong with your code but your rule configuration. Make sure to restrict your rule to only trigger on content nodes, not folder nodes. Alternatively, you could of course include a 'document.isSubType("cm:content")' check in your code and only act if that is the case.

piyush48
Active Member II

Re: Rule file moves subfolders too with original document

Jump to solution

Hi @afaust ,

Thanks it was working fine but it is moving all the documents created. i want to move document for my custom type only. I am trying to get type through this:-

var nodeType = document.properties["cmisSmiley SurprisedbjectTypeId"];

i think i am using wrong approach for getting type.

Please do help me out.

 

Thanks,

Piyush