cancel
Showing results for 
Search instead for 
Did you mean: 

Problems accessing bpm_comment variable in transition script

jdbrown
Champ in-the-making
Champ in-the-making
Using the lastest 2.1 RC.  I am trying to access the task variable bpm_comment that is part of the bpm:Task type.  I have this variable exposed in the UI fine and can fill it in and it shows up in the workflow history.  However, on the transition script, I try to assign it as a parameter into an action and it is undefined.

My script is below:

      <transition name="Submit Response" to="approve">         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">            <script>                   var action = actions.create("create-association");               action.parameters["responseText"] = bpm_comment;               action.execute(bpm_package.children[0]);               </script>         </action>      </transition>‍‍‍‍‍‍‍‍‍

I suspect I am overlooking something simple, but any ideas?
9 REPLIES 9

jdbrown
Champ in-the-making
Champ in-the-making
I also verified bpm_comment is not accessible/visible when I use the JavaScript debugger against the adhoc process definition that comes out-of-the-box.  It does however show up fine in the workflow history and in the jbpm_comments table.

The following is the detail on that task:

id: jbpm$5name: wf:submitAdhocTasktitle: Start Adhoc Taskdescription: Allocate task to colleaguestate: COMPLETEDpath: jbpm$2-@transitions: 1 transition: [default] , title: Task Done , desc: Task Doneproperties: 20 {http://www.alfresco.org/model/bpm/1.0}dueDate = null {http://www.alfresco.org/model/bpm/1.0}assignee = workspace://SpacesStore/8a393a59-3952-11dc-9dc7-b925da6b15f8 {http://www.alfresco.org/model/bpm/1.0}context = workspace://SpacesStore/2ccbd6af-3952-11dc-9dc7-b925da6b15f8 {http://www.alfresco.org/model/bpm/1.0}description = ad hoc desc {http://www.alfresco.org/model/bpm/1.0}workflowDescription = ad hoc desc {http://www.alfresco.org/model/content/1.0}created = 2007-07-23 14:40:37.0 {http://www.alfresco.org/model/bpm/1.0}workflowDueDate = null {http://www.alfresco.org/model/bpm/1.0}outcome =  {http://www.alfresco.org/model/bpm/1.0}completionDate = 2007-07-23 14:40:37.0 {http://www.alfresco.org/model/bpm/1.0}status = Completed {http://www.alfresco.org/model/content/1.0}owner = admin {http://www.alfresco.org/model/bpm/1.0}packageActionGroup = add_package_item_actions {http://www.alfresco.org/model/bpm/1.0}priority = 2 {http://www.alfresco.org/model/bpm/1.0}startDate = null {http://www.alfresco.org/model/workflow/1.0}notifyMe = false {http://www.alfresco.org/model/bpm/1.0}percentComplete = 0 {http://www.alfresco.org/model/bpm/1.0}taskId = 5 {http://www.alfresco.org/model/bpm/1.0}package = workspace://SpacesStore/96068cdd-3954-11dc-9dc7-b925da6b15f8 {http://www.alfresco.org/model/bpm/1.0}workflowPriority = 2 {http://www.alfresco.org/model/bpm/1.0}packageItemActionGroup = start_package_item_actions‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

davidc
Star Contributor
Star Contributor
Not all task variables are automatically pushed back into the workflow context and therefore available via javascript in subsequent script handlers.

In this case, bpm_comment is not transferred to the workflow context because it's actually stored on the task as a formal jbpm comment.  Only named variables assigned to the task are transferred to the workflow context.

There is a way of accessing using native jbpm support:

         <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">           <script>             <expression>               comment = "";               if (token.comments.size() > 0)                comment = token.comments.get(0).message;             </expression>             <variable name="comment" access="write"/>           </script>         </action>‍‍‍‍‍‍‍‍‍‍

This will create a comment variable in the workflow context.  Or you can just use token.comments within your script.

Workflow variable handling is still one of the areas that needs improvement, so I hope we address in future releases of Alfresco.

jdbrown
Champ in-the-making
Champ in-the-making
Thanks David.

By "workflow context" is that the same as "process variables" as described in the wiki?

Also, what do you mean by named variables assigned to the task?  The bpm_comment is a property on my task inherited from the parent bpm:Task.  Do you mean the workflow script only has access to those properties I declare myself directly on my custom task?

Would you be able to clarify in greater detail on how task and process variables are handled then?  The wiki documentation states broadly that:

"Alfresco JavaScript has access to all process variables and (if applicable) task variables, unless the <variables> element is provided, in which case, specific variables may be passed in and out of the script."

http://wiki.alfresco.com/wiki/WorkflowAdministration#Actions_.26_Scripting

Also, can you point me to some detail on the difference between the scripting syntaxes and how/if they impact what is accessible?  I have not found anything that explains teh difference between using the <expression> tag versus exlcuding it within the AlfrescoScriptAction.

If I understand what you are saying, the wiki doc is not accurate?

I apologize for so many questions.  How variables are handled and interact with scripting greatly impacts the usefulness of the Alfresco Workflow component so is a critical decision point when comparing ECM products for my client.  Thanks again for your help!

davidc
Star Contributor
Star Contributor
By "workflow context" is that the same as "process variables" as described in the wiki?

Yes

Also, what do you mean by named variables assigned to the task? The bpm_comment is a property on my task inherited from the parent bpm:Task. Do you mean the workflow script only has access to those properties I declare myself directly on my custom task?

In jBPM, a task may have an associated set of name/value pairs (or otherwise known as variables).  This allows arbitrary data to be associated with the task.  However, in jBPM, a task also supports basic built-in properties such as Id, assignee, comments, priority etc.  The properties in the Alfresco Task model either map to one of the built-in jBPM task properties or a named/value pair (if a built-in property is not appropriate).

At this time, only variables on the task are pushed back to workflow variables - not built-in task properties.  Comment is a built-in property, therefore it's not pushed back as a workflow variable.

For custom task types that derive from bpm:Task, all of their custom properties are mapped to task variables and therefore pushed back to workflow variables and accessible in script.

So, the area where I see improvements can be made, is access to task properties directly in script.  jBPM provides a 'taskInstance' variable which gives access to built-in properties and also associated name/value pairs, but the api could be simplified and made consistent with our approach to accessing properties on an Alfresco node.

Also, can you point me to some detail on the difference between the scripting syntaxes and how/if they impact what is accessible? I have not found anything that explains teh difference between using the <expression> tag versus exlcuding it within the AlfrescoScriptAction.

The expression tag alone makes no difference to what the script can achieve or has access to.  It's used primarily in conjunction with the variable tag which allows explicit control over the workflow variables that are made available to the script.  See the jBPM docs for more info.

If I understand what you are saying, the wiki doc is not accurate?

The wiki doc needs to provide more information and clarification.  I'd like to overhaul the whole workflow administration wiki to allow people to ease into workflow step-by-step.  It's a bit of chicken & egg situation - I need to find time to do that, but it's partly spent on supporting and training workflow.  The good news is that we have new engineering resource to apply to workflow.

I apologize for so many questions. How variables are handled and interact with scripting greatly impacts the usefulness of the Alfresco Workflow component so is a critical decision point when comparing ECM products for my client. Thanks again for your help!

No problem - I'm sure we have a workflow component that compares to any ECM (open or proprietary) system.  We're probably lacking in documentation and some ease-of-use.  But, that'll be resolved.

jdbrown
Champ in-the-making
Champ in-the-making
Thanks David.  Your explanation made things much clearer.  I have implemented your solution for comment already and it works perfectly.

Thanks again for the great work and great product!

jdbrown
Champ in-the-making
Champ in-the-making
David, as a follow-up question to your explanantion above, how is this handled when dealing with parallel tasks?  In other words, are the task variables still pushed up to the workflow?  I do not see that happening and wondering if that is the expected behavior for parallel tasks.

Thanks.
Jeff

lucille_arkenst
Champ in-the-making
Champ in-the-making
In response to what Jeff was saying… In my parallel review, when I try to access comments, it thinks there aren't any. But when I do a group review, it knows what comments were attached.  If anybody has an answer to this too that would be most wonderful.

joko71
Confirmed Champ
Confirmed Champ
In jBPM, a task may have an associated set of name/value pairs (or otherwise known as variables).  This allows arbitrary data to be associated with the task.  However, in jBPM, a task also supports basic built-in properties such as Id, assignee, comments, priority etc.  The properties in the Alfresco Task model either map to one of the built-in jBPM task properties or a named/value pair (if a built-in property is not appropriate).

At this time, only variables on the task are pushed back to workflow variables - not built-in task properties.  Comment is a built-in property, therefore it's not pushed back as a workflow variable.

For custom task types that derive from bpm:Task, all of their custom properties are mapped to task variables and therefore pushed back to workflow variables and accessible in script.

I have a problem of a different kind, I can't update bpm:assignee with new value in Java when updating task prior to signaling it. I have whole topic on this, but no one has answered so far:

http://forums.alfresco.com/en/viewtopic.php?f=34&t=35005

bikash
Champ in-the-making
Champ in-the-making
Hi,
How can i access the filename on which the advance workflow is trigerred inside the workflow process definition using javascript.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.