AnsweredAssumed Answered

Scripting : playing with sub space and import content

Question asked by christophes on Mar 19, 2007
Latest reply on Mar 20, 2007 by christophes
Dear,

I want to create a rule in a space A which move content, import in sub space B, into sub space defined by the date (as show in the schema below). The rule in A have to be inherited for others spaces created in A.


A
B
  Year
      Month
           Day
              <content import in B>
Actually I have a rule which create sub spaces and move imported content in. So, when I import a content in the space A, the rule moved the content in sub space defined by the date.

Example :
A
Year
     Month
          Day
             <content import in A>
The Javascript is following :
// Move document to YYYY/MM/DD structure
// First, find or create target folder

var current = document.properties["cm:created"];

var year = current.getFullYear();
var month = current.getMonth() + 1;
var day = current.getDate();

var yearSpace = space.childByNamePath(year);
if (yearSpace == null) {
   yearSpace = space.createFolder(year);
}
var monthSpace = yearSpace.childByNamePath(month);
if (monthSpace == null) {
    monthSpace = yearSpace.createFolder(month);
}
var daySpace = monthSpace.childByNamePath(day);
if (daySpace == null) {
   daySpace = monthSpace.createFolder(day);
}

// Then move document
document.move(daySpace);
The problem is how can I modify this code to create the sub spaces (Year, Month and Day) into the space of the import (B. It may have more than one space at this level) ?

Thanks in advance,

Christophe

Outcomes