sakshik

Rename a folder/File

Blog Post created by sakshik on Mar 31, 2018

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/

  • changeName.get.desc.xml 

 

<?xml version="1.0" encoding="UTF-8"?>
<webscript>
   <shortname>Rename</shortname>
   <description>Rename folder or file</description>
   <authentication>user</authentication>
   <url>/changename?dir={dirArgument}&amp;rename_to={newName}</url>
</webscript>

  •  changeName.get.html

 

<html>
   <head></head>
   <body>
      <p>Success</p>
   </body>
</html>

  • changeName.get.js

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 

Outcomes