Web script to rename a folder or a file in alfresco:
Arguments to script: alfresco ID(dir) and New name(rename_to) of the folder/file
Create 3 files in Data Dictionary/Web Scripts/
<?xml version="1.0" encoding="UTF-8"?>
<webscript>
<shortname>Rename</shortname>
<description>Rename folder or file</description>
<authentication>user</authentication>
<url>/changename?dir={dirArgument}&rename_to={newName}</url>
</webscript>
<html>
<head></head>
<body>
<p>Success</p>
</body>
</html>
var docNodeId = args.dir;
var newName = args.rename_to
function main()
{
if((docNodeId != "") && (docNodeId != null))
{
var docNode = search.findNode("workspace://SpacesStore/"+docNodeId);
docNode.name = newName
docNode.save()
}
else
{
status.setCode(404,"File name missing in the call");
}
}
main();
Refresh Web scripts.
Usage : https://<domain name>/alfresco/s/changename?dir=2e36b38b-0af9-4973-a7a4-e01869b0722c&rename_to=test