cancel
Showing results for 
Search instead for 
Did you mean: 

Script to rename document

deyvson_ti
Champ in-the-making
Champ in-the-making
Hi all,

I need a rule for rename all docs that the name contain CPF to the space.name + "CPF".

for this I created the following script:

document.name = space.name + "-CPF";
document.save();

all worked well!

but I need to do this for a large number of folders and subfolders, how i make to apply this rule for all subfolders ?

I tried to apply this rule on the main folder and selected 'Rule applies to subfolders' but has returned the name of main folder, rather than the name of space where the document was inserted.
2 REPLIES 2

ecarbenay
Star Contributor
Star Contributor
Hi,

it is because space does not refer to the parent of the document.
What you need to do is :
<javascript>
var parentFolderName = document.parent.name;
document.name = parentFolderName + "-CPF";
document.save();
</javascript>

You will have to add some controls to avoid 2 files in the same folder to get the same name, because it's not allowed.

deyvson_ti
Champ in-the-making
Champ in-the-making
Thank ecarbenay, worked great!

About duplication I will not have problems because I only need one copy of each document.

thanks !!!