Should I get a string in the context variable when I use: Context["RECIPETYPE"] = "@{Document.type}"; in a script?

When I try to set a context variable using: Context[“RECIPETYPE”] = “@{Document.type}“; I get the error below.

If I use Context[“RECIPETYPE”] = “ThisIsATestString”; everything downstream from this script line works ok.

Error log output:

2012-04-09 11:52:03,433 ERROR [org.nuxeo.ecm.automation.core.events.OperationEventListener] Failed to handle event documentCreated using chain: besCreateProcessSkinRecipe
org.nuxeo.ecm.automation.OperationException: Failed to invoke operation Context.SetVar
        at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:144)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:114)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.doInvoke(CompiledChainImpl.java:117)
        at org.nuxeo.ecm.automation.core.impl.CompiledChainImpl.invoke(CompiledChainImpl.java:96)
        at org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.run(OperationServiceImpl.java:85)
        at org.nuxeo.ecm.automation.core.events.EventHandlerRegistry.handleEvent(EventHandlerRegistry.java:198)
        at org.nuxeo.ecm.automation.core.events.PostCommitOperationEventListener.handleEvent(PostCommitOperationEventListener.java:46)
        at org.nuxeo.ecm.core.event.impl.AsyncEventExecutor$Job.run(AsyncEventExecutor.java:160)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:679)
Caused by: [Error: cannot invoke method: getVocabularyLabel]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]
        at org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
        at org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:38)
        at org.mvel2.optimizers.dynamic.DynamicGetAccessor.getValue(DynamicGetAccessor.java:66)
        at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:96)
        at org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:41)
        at org.mvel2.MVEL.executeExpression(MVEL.java:1053)
        at org.nuxeo.ecm.automation.core.scripting.MvelExpression.eval(MvelExpression.java:38)
        at org.nuxeo.ecm.automation.core.impl.OperationTypeImpl.inject(OperationTypeImpl.java:158)
        at org.nuxeo.ecm.automation.core.impl.OperationTypeImpl.newInstance(OperationTypeImpl.java:149)
        at org.nuxeo.ecm.automation.core.impl.InvokableMethod.doInvoke(InvokableMethod.java:114)
        at org.nuxeo.ecm.automation.core.impl.InvokableMethod.invoke(InvokableMethod.java:132)
        ... 25 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
        ... 35 more
Caused by: java.lang.NullPointerException
        at org.nuxeo.ecm.automation.features.PlatformFunctions.getVocabularyLabel(PlatformFunctions.java:63)
        ... 40 more
0 votes

1 answers

1301 views

ANSWER



Did you mean that you add a Execution Context > Set Context Variable operation into you operation chain definition and you set values like this:

  • name: RECIPETYPE
  • value: @{Document.type}

Because if you do

  • name: Context[“RECIPETYPE”]
  • value: @{Document.type}

You ask to automation to get the name where store the document type value into the RECIPETYPE variable.

Anyway your error is not at all expressing value you set. Did you put something like that in your chain:

@{Fn.getVocabularyLabel("voc", "key")}

The problem is more there.

0 votes



I originally tried your first example and it didnt' work. Got the error log listed.

Then I tried writing a single line script (the title of this question) to set the context variable and got the error log listed.

Yes, farther down the chain I had an @{Fn.getVocabularyLabel("ZCDVLII", RECIPETYPE) which as you said caused the error.

If I put a literal string for the value of RECIPETYPE in either case you show the @{Fn.getVocabularyLabel("ZCDVLII", RECIPETYPE) works as it should.

So it appears I cannot get the string representing the Document type from the context of this document.

04/10/2012