cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript to copy a file into new dir (trigger by rule)

gmce
Confirmed Champ
Confirmed Champ
Hi everyone, i need to create a javascript that copy a file from Data Dictionary/Models into a new folder.
I've already setup the rule to take action when a new folder is created but i have no idea how to make this javascript.

Thanks in advance.
3 REPLIES 3

jpfi
Champ in-the-making
Champ in-the-making
Hi,
first of all you should install the javascript console addon (http://code.google.com/p/share-extras/wiki/JavascriptConsole), it's a very helpful tool for such tasks.

your script should look like this (untested):

//get the node to copy
var nodeToCopy = getNodeToCopy();
//space is your current space if the JS is triggered via a rule
var yourNewNode = nodeToCopy.copy(space);

function getNodeToCopy(){
   //return your node to copy…perhaps you'll have to make a path search here…depends on your requirements
   return utils.getNodeFromString("workspace://SpacesStore/<your uid>")
}


cheers, jan

gmce
Confirmed Champ
Confirmed Champ
Hi,
first of all you should install the javascript console addon (http://code.google.com/p/share-extras/wiki/JavascriptConsole), it's a very helpful tool for such tasks.

your script should look like this (untested):

//get the node to copy
var nodeToCopy = getNodeToCopy();
//space is your current space if the JS is triggered via a rule
var yourNewNode = nodeToCopy.copy(space);

function getNodeToCopy(){
   //return your node to copy…perhaps you'll have to make a path search here…depends on your requirements
   return utils.getNodeFromString("workspace://SpacesStore/<your uid>")
}


cheers, jan

Thank you very much Jan. It works perfectly, i only changed "space" with "document" because the rule take action when a new folder is created and i needed the file to be copied inside the new folder.

Thanks again.

BTW if someone is interested here the little script:


var Subfolder1 = document.childByNamePath("Subfolder1");
Subfolder1 = document.createFolder("Subfolder1");

var Subfolder2 = document.childByNamePath("Subfolder2");
Subfolder2 = document.createFolder("Subfolder2");

   // copy Excel model
var nodeToCopy = getNodeToCopy();
var exlmodel = nodeToCopy.copy(document);
 
function getNodeToCopy(){
   return utils.getNodeFromString("workspace://SpacesStore/98a44d8a-4803-4b5f-a7c7-55def12bfb76");
}

nathanm
Champ in-the-making
Champ in-the-making
does this code also copy the comments attached in the document??
if not how does we copy a file with all the comments attached to it to a new directory??


Thanks and regards,
Nathan.