06-06-2017 10:51 AM
When using a javascript as the execute script rule on a sub folder how can I determine the name of the subfolder that I am in when the rule executes?
Our subfolders are in the name of one the files custom metadata. so when moving or copying files I would like to change this piece of metadata to the name of the folder in which the file is being placed.
So what I require is to capture the subfolder name and use this text to populate my metadata field.
Amy help would be greatly appreciated.
Thanks
06-06-2017 12:12 PM
You can access the parent folder of the rule triggering document with
document.parent
this is an alfreswco scripting node and so document.parent.name would be the name of the directory.
Another possibility is to use document.displayPath, that represents the whole path to the document as string. Splitting it by '/' would give you all pathelements...
regards,
Martin
06-06-2017 12:12 PM
You can access the parent folder of the rule triggering document with
document.parent
this is an alfreswco scripting node and so document.parent.name would be the name of the directory.
Another possibility is to use document.displayPath, that represents the whole path to the document as string. Splitting it by '/' would give you all pathelements...
regards,
Martin
06-07-2017 06:50 AM
The answer above was perfect and using the "displayPath" option enabled me to capture the last 3 folders of the path so I could determine which metadata to use. for anyone else who maybe in the same situation please find a version of my code below and I hope it can help someone in the future.
//------------------------------------------------------------
var vCurrentFolder = " "
var vElementCount = 0
var pathArray = document.displayPath.split( '/' ); // Split Path into Array by backslash
vElementCount = pathArray.length; // How many Elements in the Array
vElementCount = vElementCount - 1; // Number of Last Element
vCurrentFolder = pathArray[vElementCount]; // Load Variable with Current Folder Name
document.properties["kb:mtopic"] = vCurrentFolder ; // Load Metadata item with Current Folder name
document.save(); // Save Document Details
//-------------------------------------------------------------
Obviously by adjusting the vElementCount variable you can look as far back up the path as is possible.
Again Thank you Martin for taking the time to help me resolve this issue.
Explore our Alfresco products with the links below. Use labels to filter content by product module.