02-07-2014 06:36 AM
/**
* validates document metadata and moves to correct folder
* @author sharifu
*/
var thirdParties = document.properties["sp:thirdParties"];
var letter = "";
var location = document.properties["sp:location"];
var responsibleEmp = document.properties["sp:responsibleEmp"];
var contractRef = document.properties["sp:contractRef"];
var logNumber = document.properties["sp:logNumber"];
var effectiveDate = document.properties["sp:effectiveDate"];
var sourceFile = document;
var targetFolder = "";
var success = true;
//Check to see if values are null
if( thirdParties == null || location == "" || responsibleEmp == null || contractRef == null || logNumber == null || effectiveDate == null || location.toString() != "UK" ){
success = false;
}else{
var effectiveDate = new Date ( document.properties["sp:effectiveDate"] );
var vendor = thirdParties.replace(/[|;$%@"<>()+,\/.]/g,"").replace(".","").replace(/^\s+|\s+$/g,'');
//Check if folder exist
if(checkFolderExists(location, thirdParties )){
letter = thirdParties.charAt(0);
targetFolder = space.parent.childByNamePath(location.toString()).childByNamePath("Contracts").childByNamePath(letter.toLowerCase()).childByNamePath(vendor);
}else{
success = false; // do not move doc no folder exists
}
}
if(success){
var targetFile = targetFolder.childByNamePath(document.name);
if(targetFile == null){
sourceFile.move(targetFolder);
}else{
var targetFileWorkingCopy = targetFile.checkout();
targetFileWorkingCopy.content = sourceFile.content;
targetFileWorkingCopy.checkin("",false);
sourceFile.remove();
}
}
/** Function checks if vendor folder exists if not then it creates it
* @param String site
* @param String vendor
* @return Boolean true if creates or exists, false all others
*/
function checkFolderExists(site, thirdParties){
var vendor = thirdParties.replace(/[|;$%@"<>()+,\/.]/g,"").replace(".","").replace(/^\s+|\s+$/g,'');
var letter = vendor.charAt(0);
//.childByNamePath(letter.toLowerCase())
if( space.parent.childByNamePath(site.toString()).childByNamePath("Contracts").childByNamePath( letter.toLowerCase() ) == null ){
space.parent.childByNamePath(site.toString()).childByNamePath("Contracts").createFolder( letter.toLowerCase() );
space.parent.childByNamePath(site.toString()).childByNamePath("Contracts").childByNamePath( letter.toLowerCase() ).createFolder( vendor );
return true;
}else if( !space.parent.childByNamePath(site.toString()).childByNamePath("Contracts").childByNamePath( letter.toLowerCase() ).childByNamePath( vendor) ){
space.parent.childByNamePath(site.toString()).childByNamePath("Contracts").childByNamePath( letter.toLowerCase() ).createFolder( vendor );
return true;
}else if ( space.parent.childByNamePath(site.toString()).childByNamePath("Contracts").childByNamePath( letter.toLowerCase() ).childByNamePath( vendor) ) {
return true;
}else{
return false;
}
}
02-11-2014 05:01 AM
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.