Monday, December 28, 2009

JavaScript To Create Spaces and Move Content to specific Spaces based on Name

// JavaScript Document

var rootSpaceName = companyhome.childByNamePath("Chandu"); //returns chandu
var childList = rootSpaceName.children;
var count = childList.length;
var test = new Array();

for(var i=0; i
{
var childName = childList[i].properties.name;
var child = childList[i];

if(!child.isContainer)
{
var newSpace = childName.substring(0,4);
var ind = 0;

if(!contains(childList, newSpace, test))
{
var newSpaceName = rootSpaceName.createFolder(newSpace);
child.move(newSpaceName);
test[ind++]=newSpaceName;
}
else
{
var existingSpace = rootSpaceName.childByNamePath(newSpace);
child.move(existingSpace)
}
}
}

function contains(childList, newSpace,test)
{
for(var i = 0; i < childList.length; i++)
{
if(childList[i].properties.name == newSpace)
{
return true;
}
}
for(var i = 0; i < test.length; i++)
{
if(test[i].properties.name == newSpace)
{
return true;
}
}
return false;
}


No comments:

Post a Comment