cancel
Showing results for 
Search instead for 
Did you mean: 

Scheduled script can't find companyhome

tfrith
Champ on-the-rise
Champ on-the-rise
I'm using Alfresco Enterprise 3.2r and trying to schedule a script.
The script is deployed within an AMP and gets an error when executing saying that "companyhome" is not defined.

The same script runs fine when it is in the repository (Data Dictionary/Scripts).

How can I expose root scope javascript objects to scheduled classpath scripts?

Here is the bean definition:

<bean id="tf_test" class="org.springframework.scheduling.quartz.JobDetailBean">
   <property name="jobClass">
      <value>org.alfresco.repo.jscript.ExecuteScriptJob</value>
   </property>
   <property name="jobDataAsMap">
      <map>
         <entry key="scriptLocation">
            <bean class="org.alfresco.repo.jscript.ClasspathScriptLocation">
               <constructor-arg>
                  <value>alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js</value>
               </constructor-arg>
            </bean>
         </entry>
         <entry key="scriptService">
            <ref bean="ScriptService"/>
         </entry>
         <entry key="authenticationComponent">
            <ref bean="authenticationComponent"/>
         </entry>
         <entry key="templateActionModelFactory">
            <ref bean="templateActionModelFactory"/>
         </entry>
      </map>
   </property>
</bean>

<bean id="tf_testTrigger" class="org.alfresco.util.CronTriggerBean">
   <property name="jobDetail">
      <ref bean="tf_test" />
   </property>
   <property name="scheduler">
      <ref bean="schedulerFactory" />
   </property>

   <property name="cronExpression">
      <value>0 0/2 * * * ?</value>
   </property>
</bean>

Here is the error:

16:14:02,012 ERROR [org.quartz.core.JobRunShell] Job DEFAULT.tf_test threw an unhandled Exception:
org.alfresco.scripts.ScriptException: 04140001 Failed to execute script 'alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js': 04140000 ReferenceError: "companyhome" is not defined. (alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js#3)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:178)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:246)
   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)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceedWithAudit(AuditMethodInterceptor.java:238)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceed(AuditMethodInterceptor.java:205)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:153)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy110.executeScript(Unknown Source)
   at org.alfresco.repo.jscript.ExecuteScriptJob.execute(ExecuteScriptJob.java:86)
   at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
   at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: org.alfresco.error.AlfrescoRuntimeException: 04140000 ReferenceError: "companyhome" is not defined. (alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js#3)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:472)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:174)
   … 23 more
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "companyhome" is not defined. (alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js#3)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
   at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)
   at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3413)
   at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1612)
   at org.mozilla.javascript.gen.c1._c0(alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js:3)
   at org.mozilla.javascript.gen.c1.call(alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.gen.c1.call(alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js)
   at org.mozilla.javascript.gen.c1.exec(alfresco/module/ca.abstractive.ecm.alfresco.alfrescotoolkit/script/scheduled/test.js)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:456)
   … 24 more
3 REPLIES 3

jrott
Champ in-the-making
Champ in-the-making
Hi,

I'm also trying to schedule a script deployed in an AMP. Did you figure out how to inject the companyhome (and other root scoped objects) ?

Thanks.

tfrith
Champ on-the-rise
Champ on-the-rise
I just ended up doing a Lucene search for company home.  I'm not sure but company home may be available to the script if it is in the repository and not on the classpath.


var tmp = search.luceneSearch("PATH:\"/app:company_home\"");
var companyhome = tmp[0];

mathias_lin
Star Contributor
Star Contributor
I'm also having the same issue on 4.1.5. Did you find out how to inject the 'companyhome' reference other than using the Lucene search meanwhile?