Trying to destroy files using JavaScript

cancel
Showing results for 
Search instead for 
Did you mean: 
Pedro_Merces
Member II

Trying to destroy files using JavaScript

Hi,


I'm trying to create a JavaScript file that destroy files when possible. However, I'm not finding a way to do that since, aparently, doesn't exist a document.destroy.

Is there some especific function that does this?

15 Replies
angelborroy
Alfresco Employee

Re: Trying to destroy files using JavaScript

You may use Alfresco JSConsole addon:

https://community.venzia.es/alfresco-javascript-console/

This tools includes a full reference of Alfresco Repository JavaScript API.

Anyway, I guess you are looking for document.remove() method.

Hyland Developer Evangelist
Pedro_Merces
Member II

Re: Trying to destroy files using JavaScript

Thanks for the answer, but when I try to execute the method document.remove(), I get the following message:

"09061538 Failed to execute script 'workspace://SpacesStore/58b89198-b52b-417c-a311-e9cc1c4f4fc3': Node does not exist: workspace://SpacesStore/60f67e94-6e73-42a2-8f3b-7eefc5e174f0 (statusSmiley Frustratedtatus[id=85115changeTxnId=0f6fd51b-248e-4cd8-b3d9-c1bcf4d43649, dbTxnId=13929, deleted=true])"

Besides that, the addon just make things easier when it comes to test the script, anyway, I don't have the possibility of installing an addon such as the JSConsole, so this option is unviable.

angelborroy
Alfresco Employee

Re: Trying to destroy files using JavaScript

Probably you're trying to remove the document in the same DB Transaction you are creating it.

That operation is not supported, since every JS script runs in a single DB Transaction.

Hyland Developer Evangelist
Pedro_Merces
Member II

Re: Trying to destroy files using JavaScript

My document was already created before the script and the only change I'm making is switch a option on the metadata to trigger the script.

To exclusively test this, my code is only the method Document.remove(), I've already tried Document.parent.remove(), but both of them gives the same error.

angelborroy
Alfresco Employee

Re: Trying to destroy files using JavaScript

I made a simple tests and document.remove() works as expected.

I guess the problem is related with the metadata updating, since the document is removed and after that Alfresco is trying to update that metadata property. May you try triggering removal by using some other method?

Hyland Developer Evangelist
afaust
Master

Re: Trying to destroy files using JavaScript

Or alternatively, provide the actual script that you are trying to execute, instead of just the single instruction. As well as the whole stacktrace that belongs to the error, not just the message. That way it'd be a lot easier to help pinpoint the cause of it.

Pedro_Merces
Member II

Re: Trying to destroy files using JavaScript

I made some changes and the function worked, but thats not what I am looking for. The method document.remove() deletes the document, I want to destroy it, preservating the metadata of the file.

angelborroy
Alfresco Employee

Re: Trying to destroy files using JavaScript

document.content = "";
Hyland Developer Evangelist
Pedro_Merces
Member II

Re: Trying to destroy files using JavaScript

My objective isn't erasing the content of my file, it is to use the destroy function of alfresco through JavaScript.