AnsweredAssumed Answered

Update a document with rule and scripts

Question asked by agey on Jun 29, 2010
Latest reply on Jun 29, 2010 by agey
Hi all,

I want to create a rule to update a document. I have some documents in a space and every day this documents must be updated with the content of another document. It means, I have the document A in Space A and when document B is added in Space B I want to update document A with the content of the document B.

I tried the following script but the content of document A become white:


var nombrepdf = document.name;
var nombrepai = nombrepdf.replace("OCR_","");
var nodepai = space.parent;
var documentA= nodepai.childByNamePath(nombrepai);

if (documentA != null)
{
documentA.content = document.content;
document.remove();
}

I tried this other script but it returns an error. I want to replace document B by document A so I move document B to the same space that document A and then I add to document B the properties of document A.


var nombrepdf = document.name;
var nombrepai = nombrepdf.replace("OCR_","");
var nodepai = space.parent;
var documentA= nodepai.childByNamePath(nombrepai);

if (documentA != null)
{
document.move(nodepai);
document.properties =  documentA.properties;
documentA.remove();
}
   

And the error is this:

10:27:55,703 ERROR [org.alfresco.web.ui.common.Utils] Ocurrió un error del sistema durante la operación: Failed to execute script 'workspace://SpacesStore/941bd772-00f1-448a-afa5-d42f5d4ba8ab': Java class "org.alfresco.repo.jscript.ScriptNode" has no public instance field or method named "properties". (AlfrescoScript#27)
org.alfresco.scripts.ScriptException: Failed to execute script 'workspace://SpacesStore/941bd772-00f1-448a-afa5-d42f5d4ba8ab': Java class "org.alfresco.repo.jscript.ScriptNode" has no public instance field or method named "properties". (AlfrescoScript#27)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:156)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:176)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)

How can I update document A with the content of document B using scripts and rules? Are there any javascript method to update a document?

Thanks a lot in advance,

Outcomes