AnsweredAssumed Answered

trouble accessing document properties in workflow script

Question asked by luca.dallolio on Dec 16, 2008
Latest reply on Dec 19, 2008 by luca.dallolio
Hi to everyone, while trying to access (alfresco labs 3.0.0 (c 1342)) a document property from an advanced workflow script, I run against a number of issues, such as a NullPointerException. For instance, this syntax will not work (nor I could find the logger variable) :


   <task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
            <script>
               System.out.println("property : " + bpm_package.children[0].properties.myproperty);
         </script>
         </event>
      </task>
      <transition name="" to="completed" />
   </task-node>

By reading alfresco sources, I managed to find out a working syntax, but rather awkward imho with respect to the wiki :


   <task-node name="adhoc">
      <task name="wf:adhocTask" swimlane="assignee">
         <event type="task-create">
            <script>
            org.mozilla.javascript.Context.enter();
            org.mozilla.javascript.Scriptable scope = org.mozilla.javascript.Context.getCurrentContext().initStandardObjects();
            bpm_package.setScope(scope);
            System.out.println("property before : " + bpm_package.children.get(0, null).properties.get("{http://acme.com/model/customer1/content/1.0}myproperty"));
            bpm_package.children.get(0, null).properties.put("{http://acme.com/model/customer1/content/1.0}myproperty','NewValue");                     
            bpm_package.children.get(0, null).save();
            System.out.println("property after : " + bpm_package.children.get(0, null).properties.get("{http://acme.com/model/customer1/content/1.0}myproperty"));
         </script>
         </event>
      </task>
      <transition name="" to="completed" />
   </task-node>

As I said, this code will work, but should be much easier, shouldn't it?

Deatils over the exception with the first snippet (caused by bpm_package not having a context, not having a scope etc.) :


19:36:37,980 WARN  [graph.action.Script] exception during evaluation of script expression
Sourced file: inline evaluation of: ``                System.out.println("property before : " + bpm_package.children[0]. . . . '' : Property accessor threw exception: java.lang.NullPointerException : at Line: 2 : in file: inline evaluation of: ``                System.out.println("property before : " + bpm_package.children[0]. . . . '' : bpm_package .children

   at bsh.UtilEvalError.toEvalError(Unknown Source)
   at bsh.UtilEvalError.toEvalError(Unknown Source)
   at bsh.BSHAmbiguousName.toObject(Unknown Source)
   at bsh.BSHAmbiguousName.toObject(Unknown Source)
   at bsh.BSHPrimarySuffix.doSuffix(Unknown Source)
   at bsh.BSHPrimaryExpression.eval(Unknown Source)
   at bsh.BSHPrimaryExpression.eval(Unknown Source)
   at bsh.BSHBinaryExpression.eval(Unknown Source)
   at bsh.BSHArguments.getArguments(Unknown Source)
   at bsh.BSHMethodInvocation.eval(Unknown Source)
   at bsh.BSHPrimaryExpression.eval(Unknown Source)
   at bsh.BSHPrimaryExpression.eval(Unknown Source)
   at bsh.Interpreter.eval(Unknown Source)
   at bsh.Interpreter.eval(Unknown Source)
   at bsh.Interpreter.eval(Unknown Source)
   at org.jbpm.graph.action.Script.eval(Script.java:130)
   at org.jbpm.graph.action.Script.eval(Script.java:73)
   at org.jbpm.graph.action.Script.execute(Script.java:62)
   at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:264)
   at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:220)
   at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:190)
   at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:174)
   at org.jbpm.taskmgmt.exe.TaskInstance.create(TaskInstance.java:170)
   at org.alfresco.repo.workflow.jbpm.WorkflowTaskInstance.create(WorkflowTaskInstance.java:107)
        …

Am I doing something wrong here? Would you like me to provide more detail about this, or submit a Jira Issue?
Thanks in advance,
Luca

Outcomes