cancel
Showing results for 
Search instead for 
Did you mean: 

How to move or remove a document using the JavaScript API

lcandido
Champ in-the-making
Champ in-the-making
I'm trying to build a simple workflow. A document arrives in a space and must be copied to another one and moved to a third one. Or copied and removed, it's OK too. It's easy to use a script within a Content Rule to copy it, but how can I move or remove the document? Just "document.remove()" doesn't work!

Thanks for any help.
8 REPLIES 8

parzgnat
Star Contributor
Star Contributor
If you're using the Alfresco JavaScript API, the call to remove a node must be called from the parent of the node that you want to delete.  The call looks like this:
parentNode.removeNode(childNode);

Full JavaDoc of the JavaScript API of node can be found here
http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/repo/jscript/ScriptNode.html

lcandido
Champ in-the-making
Champ in-the-making
… as said The Beatles.

I've tried to use your tip, but I'm really beginning. The code

var pai = document.getParent()
var no = document.getNodeRef()
(call) pai.removeNode(no)

hasn't worked. Would you extend your explanation with a functional example?

More: Thanks to "Class ScriptNode" I've found the method "public boolean move(ScriptNode destination)" that will be very useful. Would be possible to send a short example?

Thanks a lot,

kaynezhang
World-Class Innovator
World-Class Innovator
You can  just delete the node by using node.remove(),this method returns true on success, false otherwise
If you want to get it's parent please use node.parent(return primary parent node),or node.parents.

kaynezhang
World-Class Innovator
World-Class Innovator
You can  just delete the node by using node.remove(),this method returns true on success, false otherwise
If you want to get it's parent please use node.parent(return primary parent node),or node.parents.

lcandido
Champ in-the-making
Champ in-the-making
I've tried:

var no = document.getNodeRef()
var success = no.remove()

var pai = document.getParent()
var success = pai.removeNode(no)

var no = document.properties.node-uuid
var success = no.remove()

No success at all. Please, just one example!

kaynezhang
World-Class Innovator
World-Class Innovator
By using document root object ,I guess you want to execute javascripts from the Data Dictionary on current document.Follow below
steps:
1.Create a file called testremove.js(or any name) and store it in Company Home>Data Dictionary>Scripts folder

if (document.mimetype == "application/msword")
{
   document.remove();
}


2.upload an ms word document in a space. for example, upload a document named toremove.doc.
3.open the details view of the document. Click on Run Action and select Execute script. You can see your new script testremove.js ,select it and click OK.
4.Click on Finish to execute the action. This will run your javascript and your toremove.doc will be removed.

lcandido
Champ in-the-making
Champ in-the-making
All this time I was working on a JavaScript code at space "data dictonary/scripts". But now the code is running. I belive the testing mode was wrong.

Thanks for your helpful answer. 

gangadharjwala
Champ in-the-making
Champ in-the-making
Hi All,

i am a new for alfresco.Can any one help me out how to "Delete a specific version document using web services or using java script"