cancel
Showing results for 
Search instead for 
Did you mean: 

Passing variabl to a shell task

dmill
Champ in-the-making
Champ in-the-making
Hello guy,

I'm using Activiti-rest and having a hard time figuring out how to use variables in a shell task.

I create a process instance using POST runtime/process-instances:
{
   'processDefinitionId':'xxxxx',
   'variables' : [
     {'name' : 'myVar', 'value' : 'something'}
   ]
}

And my process definition contains:


<serviceTask id="console" activiti:type="shell" >
   <extensionElements>
      <activiti:field name="command" stringValue="echo" />
      <activiti:field name="arg1" stringValue="${scriptVar}" /> 
   </extensionElements>
</serviceTask>

But this doesn't work. The process runs properly otherwise.

Any help would be appreciated.
12 REPLIES 12

dmill
Champ in-the-making
Champ in-the-making
Let me just correct that, I'm obviously using ${myVar}. Sorry for the confusion, still need help though.

trademak
Star Contributor
Star Contributor
Could you elaborate a bit more on "this doesn't work"?

Best regards,

dmill
Champ in-the-making
Champ in-the-making
Thanks for taking the time to answer.

By "this doesn't work" I mean that ${myVar} seems null. As a testable example we could say that if we defined myVar = /tmp/thing.txt

then when trying the above replacing "echo" with "touch" then
touch ${myVar} should create a file but doesn't

If I replace ${myVar} by the actual path  I get :
touch /tmp/thing.txt And this works correctly and creates the file.

dmill
Champ in-the-making
Champ in-the-making
Just to make sure it's clear with everyone.

I create a process instance using POST runtime/process-instances:

{
   'processDefinitionId':'xxxxx',
   'variables' : [
     {'name' : 'myPath', 'value' : '/tmp/test.txt'}
   ]
}
And my process definition contains:

<serviceTask id="console" activiti:type="shell" >
   <extensionElements>
      <activiti:field name="command" stringValue="touch" />
      <activiti:field name="arg1" stringValue="${myPath}" /> 
   </extensionElements>
</serviceTask>

The above does not create a file at /tmp/test.txt
But the code bellow does :


<serviceTask id="console" activiti:type="shell" >
   <extensionElements>
      <activiti:field name="command" stringValue="touch" />
      <activiti:field name="arg1" stringValue="/tmp/test.txt" /> 
   </extensionElements>
</serviceTask>

Can anyone tell me how to properly use the variables I sent to the process?

Thanks

jbarrez
Star Contributor
Star Contributor
Have you verified the variable is tored in the database, or by printing it out before your shell task?

I havent got the code in front of me, but it might be good to check if the shellTaskActivityBehavior supports expressions, and not just regular strings as fields.

dmill
Champ in-the-making
Champ in-the-making
Thanks a lot for taking the time to reply. Yes the variables are properly set.
There was a previous post where this question was asked ands resolved but I fail to understand the answer that was given. Any clarification would be great. here's the link:

http://forums.activiti.org/content/accessing-form-variable-subsequent-shell-task

Thanks in advance.

dmill
Champ in-the-making
Champ in-the-making
Hey guys,

I don't mean to be insistant but this is proving to be a huge sticking point for us. And we're stuck until we find a solution. I would find it odd that a shell Task wouldn't accept expressions (really defeats the purpose) so I'm sure it's just a matter of figuring out how to get the functionality to work.
Like I posted earlier. An explanation was given to the same problem and I just don't know how to interpret it. Where do I put my expression?

dmill
Champ in-the-making
Champ in-the-making
anyone?

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi


  <serviceTask id="shellEcho" activiti:type="shell">
   <extensionElements>
    <activiti:field name="command" stringValue="cmd" />
    <activiti:field name="arg1" stringValue="/c" />
    <activiti:field name="arg2" stringValue="echo" />
    <activiti:field name="arg3" stringValue="EchoTest" />
    <activiti:field name="wait" stringValue="true" />
    <activiti:field name="outputVariable" stringValue="resultVar"/>
   </extensionElements>
  </serviceTask>

arg1..3 can be expressions (e.g. use ${varName} )

Regards
Martin