cancel
Showing results for 
Search instead for 
Did you mean: 

Action 'Transform Object' but copy N O T to anot

schneika
Champ in-the-making
Champ in-the-making
The Standard Action "Transform Object and copy to another place" copies like expected the transformed object  to another place. But i need to modify the Action so that the transformed object should generated automatically in the same smartspace where the original resists, so that i can use this action in a rule for all Smartspaces and the Children within.
How can i modify this Transform-Object-Action (without the "copy to another place"-aspect)?
Any suggestions  :?:
6 REPLIES 6

kevinr
Star Contributor
Star Contributor
By far the easiest way to do this is using a JavaScript based rule (Execute a Script) - everything you want to do can be done this way. A JavaScript rule can execute transformations, move objects, add aspects, rename items etc. etc.
http://wiki.alfresco.com/wiki/JavaScript_API

Thanks,

Kevin

schneika
Champ in-the-making
Champ in-the-making
Now i have create a Javascript named Tranform2HTML.js like described in the JavaScript-API:

// Transform-Convert to HTML
var trans1 = transformDocument("text/html");

I use V2.1.0 CE Final and call the script from an Smartspace-Rule as an Action.
In the Smartspace there are only some MS-EXCEL-Files.xls, but they wont convert to html.

The alfresco.log cries:

10:59:02,679 ERROR [org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl] Failed to execute asynchronous action: Action[ id=9bae1027-6c0e-11dc-b8a8-ab770b6e9f06, node=workspace://SpacesStore/9bae1027-6c0e-11dc-b8a8-ab770b6e9f06 ]
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/ed31b56f-6c0b-11dc-b8a8-ab770b6e9f06': Failed to execute script 'workspace://SpacesStore/ed31b56f-6c0b-11dc-b8a8-ab770b6e9f06': ReferenceError: "transformDocument" is not defined. (AlfrescoScript#2)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:171)
   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:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy48.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:157)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
   at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:72)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:472)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1.execute(AsynchronousActionExecutionQueueImpl.java:258)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:225)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper.run(AsynchronousActionExecutionQueueImpl.java:267)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
   at java.lang.Thread.run(Thread.java:595)
Caused by: org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/ed31b56f-6c0b-11dc-b8a8-ab770b6e9f06': ReferenceError: "transformDocument" is not defined. (AlfrescoScript#2)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:146)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:167)
   … 33 more
Caused by: org.alfresco.error.AlfrescoRuntimeException: ReferenceError: "transformDocument" is not defined. (AlfrescoScript#2)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:518)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:142)
   … 34 more
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "transformDocument" is not defined. (AlfrescoScript#2)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3226)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3216)
   at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3289)
   at org.mozilla.javascript.ScriptRuntime.getNameFunctionAndThis(ScriptRuntime.java:1891)
   at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:93)
   at org.mozilla.javascript.gen.c1._c0(AlfrescoScript:2)
   at org.mozilla.javascript.gen.c1.call(AlfrescoScript)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
   at org.mozilla.javascript.gen.c1.call(AlfrescoScript)
   at org.mozilla.javascript.gen.c1.exec(AlfrescoScript)
   at org.mozilla.javascript.Context.evaluateString(Context.java:1144)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:510)
   … 35 more

Whats going wrong with my little script?

kevinr
Star Contributor
Star Contributor
I assume you have the node you want to convert?

var trans1 = document.transformDocument("text/html");

schneika
Champ in-the-making
Champ in-the-making
:idea: thanx a lot, now its ok:

// Transform-Convert to HTML 
var trans1 = document.transformDocument("text/html");

schneika
Champ in-the-making
Champ in-the-making
:idea: thanx a lot, now its ok:

// Transform-Convert to HTML 
var trans1 = document.transformDocument("text/html");

This JavaScript can be called from an Action-Rule in Smartspaces with the regular conditions and transforms any Content to HTML. The Script creates a new Content/Document with mimetype .html
But when i modify the originalcontent in the smartspace within this actionrule, then the newly transformed Content can not overwrite the already present HTML-Content.
How can i manage so that the script will be able to overwrite after tranforming an already existing content/document without this error (DuplicateChildNodeName should be allowed):

15:55:38,145 ERROR [org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl] Failed to execute asynchronous action: Action[ id=2c35c877-6c14-11dc-b8a8-ab770b6e9f06, node=workspace://SpacesStore/2c35c877-6c14-11dc-b8a8-ab770b6e9f06 ]
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/ed31b56f-6c0b-11dc-b8a8-ab770b6e9f06': Failed to execute script 'workspace://SpacesStore/ed31b56f-6c0b-11dc-b8a8-ab770b6e9f06': Wrapped org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: PB AM Reparatur TIB.html (AlfrescoScript#2)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:171)
   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:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy48.executeScript(Unknown Source)
   at org.alfresco.repo.action.executer.ScriptActionExecuter.executeImpl(ScriptActionExecuter.java:157)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
   at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:72)
   at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:120)
   at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:537)
   at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:472)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1.execute(AsynchronousActionExecutionQueueImpl.java:258)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:225)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:155)
   at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper.run(AsynchronousActionExecutionQueueImpl.java:267)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
   at java.lang.Thread.run(Thread.java:595)
Caused by: org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'workspace://SpacesStore/ed31b56f-6c0b-11dc-b8a8-ab770b6e9f06': Wrapped org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: PB AM Reparatur TIB.html (AlfrescoScript#2)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:146)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:167)
   … 33 more
Caused by: org.alfresco.error.AlfrescoRuntimeException: Wrapped org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: PB AM Reparatur TIB.html (AlfrescoScript#2)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:518)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:142)
   … 34 more
Caused by: org.mozilla.javascript.WrappedException: Wrapped org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: PB AM Reparatur TIB.html (AlfrescoScript#2)
   at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1705)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:157)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:201)
   at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:64)
   at org.mozilla.javascript.gen.c1._c0(AlfrescoScript:2)
   at org.mozilla.javascript.gen.c1.call(AlfrescoScript)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:337)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2755)
   at org.mozilla.javascript.gen.c1.call(AlfrescoScript)
   at org.mozilla.javascript.gen.c1.exec(AlfrescoScript)
   at org.mozilla.javascript.Context.evaluateString(Context.java:1144)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:510)
   … 35 more
Caused by: org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: PB AM Reparatur TIB.html
   at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.setChildNameUnique(HibernateNodeDaoServiceImpl.java:698)
   at sun.reflect.GeneratedMethodAccessor432.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)

Please can you help me?  :?:

kevinr
Star Contributor
Star Contributor
You can rename the old object or delete it. If you are using latest code (after 2.1 community) or 2.1E then you can use the  write(ScriptContent content)  API.

Thanks,

Kevin