AnsweredAssumed Answered

Control version storage bloat with Javascript?

Question asked by sarnold on Oct 26, 2011
Latest reply on Oct 28, 2011 by sarnold
Hi All,

We are currently trailing Alfresco Community 4.0a with a view to using it in-house for document storage and management.

Firstly, none of this would be needed except that so far as I can see there is no way in Alfresco to limit the number of document versions that can be created.
So if I've missed something obvious please correct my understanding.

So I thought that perhaps we could put the "brakes" on an ever increasing file-store size by using a Javascript rule. Something along the lines of (in pseudo code):-

1. On document update check if document has the "versionable aspect":-
2. If it does then check the number if versions currently stored:-
3. If the number of versions is greater than say 10 then:-
4. Create a new document and fill it with lets say the most recent three versions of the document in question.
(we have to do it this way I guess because the javascript API appears to have NO mechanism for deleting a specific document version - true?)
5. Now delete the original
6. Then rename the new to match the original name.

So that's what I'm trying to do. If there is an easier way then please point me in the right direction.

My problem is I don't understand how to use document.versionHistory; and document.getVersion(); properly.

document.versionHistory returns an array like this:-


(14 lines above one for each document version saved)

Disconcertingly every time the script is run the @hexadecimal numbers appear to all be totally different.

And if I try to retrieve a version of the document using say:-


It just generates an error in the server side Javascript debugger saying that "org.alfresco.repo.jscript.ScriptVersion@240f767d" does not exist in version store "Workspace://SpaceStore/great-long-string-of-hex-digits"

Can someone give me just a few pointers on how I'm supposed to correctly use the Javascript 4.0 API to access and control document revisions?


Cheers Steve.

Update 1:

Using the Share Node browser I was able to verify that the store workspace being referenced by document.getVersion() was the node of the actual script and not the document.

I found that:-


will execute without error. But:-

oldDoc = space.getVersion("org.alfresco.repo.jscript.ScriptVersion@240f767d");

Just assigns Null to oldDoc.

How does one use the getVersion API call?