AnsweredAssumed Answered

Workflow woes: accessing task variables doesn't work

Question asked by marcus on Jan 23, 2008
Latest reply on Jan 30, 2008 by bedag-moo
I'm trying to access a task variable (bpm_comment) during the end-task event so that I can track comments all the way through to the end to use in a checkin process. As per http://wiki.alfresco.com/wiki/WorkflowAdministration#Process_Data, I expected bpm_comment to be pulled into the list of variables I could read in the action block.


<event type="task-end">
   <action class="com.lateralminds.alfresco.jbpm.jscript.SystemAlfrescoJavaScript">
     <script>
         var currentComments = bpm_package.properties['cwfl:commentHistory'];
         
         if (currentComments == null) {
            currentComments = new Array();
         }

         currentComments[currentComments.length] = bpm_comment;
         bpm_package.properties['cwfl:commentHistory'] = currentComments;
         bpm_package.save();
     </script>
   </action>
</event>

(the SystemAlfrescoJavaScript class is basically a copy of the alfresco script handler just running as the system user as per the 2.9 version does things)

The cwfl:commentHistory is part of an aspect I have applied to the package at the start of the workflow so that I can store the comments from all the reviewers. Every time this block is executed, bpm_comment is undefined. I have overridden its definition so that it is a mandatory property, so it is definitely being set by the user. I have tried in other blocks of the task and it looks like NONE of the task variables are being pulled into the global scope (looking at it from the JS debugger). Is it possible that the script running as the system user means that none of the task variables are being loaded?

Further looking shows that in org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript::createInputMap, the method call to

Map<String, Object> variables = contextInstance.getVariables(token);

is only returning the process instance variables


{bpm_package=
Node Type: {http://www.alfresco.org/model/content/1.0}systemfolder,
Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/bpm/1.0}workflowPackage, {http://www.lateralminds.com.au/workflow/curtin/policy/1.0}historyTrackable],
initiator=
Node Type: {http://www.alfresco.org/model/content/1.0}person,
Node Aspects: [{http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/application/1.0}configurable],
bpm_workflowDueDate=
null,
bpm_context=
Node Type: {http://www.alfresco.org/model/content/1.0}folder,
Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable],
initiatorhome=
Node Type: {http://www.alfresco.org/model/content/1.0}folder,
Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable],
bpm_status=Completed,
bpm_outcome=,
bpm_packageActionGroup=
add_package_item_actions,
cancelled=
false,
bpm_workflowDescription=
aefwaef,
bpm_packageItemActionGroup=
start_package_item_actions,
bpm_workflowPriority=2,
companyhome=
Node Type: {http://www.alfresco.org/model/content/1.0}folder,
Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable],
bpm_percentComplete=0
}

Edit: This is alfresco 2.1.1

Outcomes