When using an Execute Script Rule how can I determine the name of the subfolder that I am in when the rule executes?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

When using an Execute Script Rule how can I determine the name of the subfolder that I am in when the rule executes?

Jump to solution

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

1 Solution

Accepted Solutions
Highlighted
Senior Member II

Re: When using an Execute Script Rule how can I determine the name of the subfolder that I am in when the rule executes?

Jump to solution

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

View solution in original post

2 Replies
Highlighted
Senior Member II

Re: When using an Execute Script Rule how can I determine the name of the subfolder that I am in when the rule executes?

Jump to solution

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

View solution in original post

Highlighted
Active Member

Re: When using an Execute Script Rule how can I determine the name of the subfolder that I am in when the rule executes?

Jump to solution

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.