02-05-2014 02:41 PM
var pathToDataList="Sites/reports/dataLists/";
var dataListName="Reports Recipients";
var docAspect="ra:reportProperties";
var reportLists = companyhome.childByNamePath(pathToDataList).getChildren();
var goodDoc=true;
var reportList;
var siteShortName="";
for each (child in reportLists)
{
if (child.properties["cm:title"]==dataListName)
{
reportList=child;
goodDoc=true;
break;
}
else
{
goodDoc=false;
}
}
if (!document.hasAspect(docAspect))
{
document.addAspect(docAspect);
document.save();
}
var filenameArray=new Array();
var reportName=document.properties.name;
var today=new Date();
var thisYear=today.getFullYear();
var thisDate=today.getFullYear()+"-"+(today.getMonth()+1)+"-"+today.getDate();
var reportNameArray=reportName.split(".");
var reportNameWithoutExtension=reportNameArray[0];
filenameArray=reportNameWithoutExtension.split("-");
var uniqueIdentifier=(filenameArray[0]).replace(/^\s+|\s+$/g, '');
document.properties.description=uniqueIdentifier;
document.save();
var firstBracketPosition=reportName.indexOf('[');
var lastBracketPosition=reportName.indexOf(']');
var suffix="";
if ((lastBracketPosition-firstBracketPosition)>1)
{
suffix=reportName.substring(firstBracketPosition,lastBracketPosition+1);
}
document.properties.description+="mingood";
document.save();
var fallback=false;
var fallbackOverride=false;
var fallbackDepartment="";
var fallbackReportName="";
if (goodDoc)
{
document.properties.description+="goodDoc";
document.save();
var items=reportList.getChildren();
for each (child in items)
{
if (uniqueIdentifier==child.properties["reportdl:uniqueIdentifier"])
{
if (child.properties["reportdl:suffix"].length>0 && suffix.indexOf(child.properties["reportdl:suffix"])>0)
{
document.properties.description+="suffixGood";
document.save();
fallbackOverride=true;
document.properties["ra:uniqueIdentifier"]=(uniqueIdentifier.replace("$","_")).replace("#","_");
document.properties["ra:reportName"]=child.properties["reportdl:reportName"];
document.properties["ra:date"]=today;
document.properties["ra:department"]=child.properties["reportdl:department"];
document.properties["ra:notInWorkflow"]=true;
if ((child.properties["reportdl:suffix"]!=null))
{
document.properties["ra:suffix"]=child.properties["reportdl:suffix"];
}
document.save();
var sortedFoldersHome=companyhome.childByNamePath("Sites/reports/documentLibrary/Sorted-Folders");
var department=sortedFoldersHome.childByNamePath(document.properties["ra:department"]);
if (department==null)
{
department=sortedFoldersHome.createFolder(document.properties["ra:department"]);
}
var years = companyhome.childByNamePath("Sites/reports/documentLibrary/Sorted-Folders/"+document.properties["ra:department"]).getChildren();
var destinationParent;
var parent=companyhome.childByNamePath("Sites/reports/documentLibrary/Sorted-Folders/"+document.properties["ra:department"]);
var goodDoc2=false;
for each (child in years)
{
var childYear = child.properties.name;
if (childYear==thisYear)
{
destinationParent=child;
goodDoc2=true;
break;
}
}
if (goodDoc2) //if the Sorted-Folders/YYYY path is found, move the document to the correct sub-directory
{
var goodDoc3=true;
var dates=destinationParent.getChildren();
for each (child in dates)
{
var childDate=child.properties.name;
if (childDate==thisDate)
{
document.move(child);
goodDoc3=false;
break;
}
}
if (goodDoc3)
{
var dateFolder=destinationParent.createFolder(thisDate);
document.move(dateFolder);
}
}
else
{
var yearFolder = parent.createFolder(thisYear);
var dateFolder = yearFolder.createFolder(thisDate);
document.move(dateFolder);
}
break;
}
else if (child.properties["reportdl:suffix"]=="Nil")
{
fallback=true;
fallbackDepartment=child.properties["reportdl:department"];
fallbackReportName=child.properties["reportdl:reportName"];
}
}
else
{
document.properties["ra:uniqueIdentifier"]=(uniqueIdentifier.replace("$","_")).replace("#","_");
document.properties["ra:reportName"]=(uniqueIdentifier.replace("$","_")).replace("#","_");
document.properties["ra:date"]=today;
document.properties["ra:department"]="Unknown";
document.properties["ra:notInWorkflow"]=true;
document.save();
}
}
if (fallback && !fallbackOverride)
{
document.properties.description="fallbackGood "+fallbackReportName+fallbackDepartment;
document.properties["ra:uniqueIdentifier"]=(uniqueIdentifier.replace("$","_")).replace("#","_");
document.properties["ra:reportName"]=fallbackReportName;
document.properties["ra:date"]=today;
document.properties["ra:department"]=fallbackDepartment;
document.properties["ra:notInWorkflow"]=true;
document.properties["ra:suffix"]="Nil";
document.save();
var sortedFoldersHome=companyhome.childByNamePath("Sites/reports/documentLibrary/Sorted-Folders");
var department=sortedFoldersHome.childByNamePath(document.properties["ra:department"]);
if (department==null)
{
department=sortedFoldersHome.createFolder(document.properties["ra:department"]);
}
var years = companyhome.childByNamePath("Sites/reports/documentLibrary/Sorted-Folders/"+document.properties["ra:department"]).getChildren();
var destinationParent;
var parent=companyhome.childByNamePath("Sites/reports/documentLibrary/Sorted-Folders/"+document.properties["ra:department"]);
var goodDoc2=false;
for each (child in years)
{
var childYear = child.properties.name;
if (childYear==thisYear)
{
destinationParent=child;
goodDoc2=true;
break;
}
}
if (goodDoc2) //if the Sorted-Folders/YYYY path is found, move the document to the correct sub-directory
{
var goodDoc3=true;
var dates=destinationParent.getChildren();
for each (child in dates)
{
var childDate=child.properties.name;
if (childDate==thisDate)
{
document.move(child);
goodDoc3=false;
break;
}
}
if (goodDoc3)
{
var dateFolder=destinationParent.createFolder(thisDate);
document.move(dateFolder);
}
}
else
{
var yearFolder = parent.createFolder(thisYear);
var dateFolder = yearFolder.createFolder(thisDate);
document.move(dateFolder);
}
}
}
02-10-2014 01:46 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.