I have created the below folder rule javascript which is intended to the the following:
Checks to see if a folder exists based on text in the document description, if the folder exists, move the file to that found folder. If not, create the subsequent folder stucture Year > Month Name > Date > CIF, then move the file to the resulting CIF folder. I can get certain segments of code to work in isolation within the javascript console, but cannot get it to fire when plugged into the server rule. Would appreciate any advice, code below:
var d = new Date(); var n = d.getFullYear(); var m = d.getMonth(); var o = d.getDate(); var Descr = document.properties["description"]; var CIF = Descr.substring(3, 8); var yearFolder = space.childByNamePath(n); var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; var thisMonth = months[m]; var monthFolder = yearFolder.childByNamePath(thisMonth); var dateFolder = monthFolder.childByNamePath(o); var cifFolder = dateFolder.childByNamePath(CIF); var foundFolder = search.luceneSearch("TYPE:\"acme:folder\"" + CIF); function main() { if (foundFolder == null) { if (yearFolder == null) { //create year folder yearFolder = space.childByNamePath.createFolder(n); } if (monthFolder == null) { //create month folder by month-name monthFolder = yearFolder.childByNamePath.createFolder(thisMonth); } if (dateFolder == null) { //create month date folder dateFolder = monthFolder.childByNamePath.createFolder(o); } if (cifFolder == null) { //create CIF folder based on file CIF12345 description cifFolder = dateFolder.childByNamePath.createFolder(CIF); } //move file to CIF folder var move1 = document.move(cifFolder); } else { var move2 = document.move(foundFolder); } } main();
do you get any errors in the logs? how have you configured the rule fom share?
Sorry I am very new to Alfresco, I'm not sure how to check the logs. The rule is configured from Share as a folder rule that fires when a document in the folder is modified. If the description contains CIFXXXXX it will fire the script above.
maybe you should add some code for easier debugging:
function logMe(message) { var d = new Date(); var ds = utils.toISO8601(d) + ""; logger.system.out(ds.replace("T", " ").trim() + " " + script.name + ": " + message); }
add the logMe function to your code and call it to test your expected variable values, look if your script is triggered with
logMe("script is triggered"); on startup
The output is visible i.e. on in the catalina.out
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.