accessing a process variable from a powershell script
Hi everybody,
I'm new to bonita and while playing around I get stuck when I try to use a process variable inside a (otherwise unmeaningful) powershell script called from script-connector.
Pressing ctrl+space inside the script pane shows the process variables defined. Clicking on the desired one makes it appear as ${myProcessVariable}.
Unfortunately it never gets used in the script, neither with curly brackets nor without...
ps-code goes like this:
$myVar = ${myProcessVariable}
$myOutVar = "#"
for ($i=0; $i -lt $myVar.length; $i++){
$myOutVar += $myVar.Substring($i) + "#"
}
return $myOutVar
Running the process at least gives back '#' but nothing else.
What is the preferred way to access a process variable? What am I missing?
Help is greatly appreciated.
Martin
Hi,
I would avoid using the `${...}` format in your case as this could be mis-interpreted in a Shell environment.
Instead, generate your script with a Groovy/Java script such as this:
String shellScript = "$myVar = "+ myProcessVariable +"\n" shellScript += "$myOutVar = \"#\"\n" shellScript += "for ($i=0; $i -lt $myVar.length; $i++){\n" shellScript += "$myOutVar += $myVar.Substring($i) + \"#\"\n" shellScript += "}\n" shellScript += return $myOutVar\n" return shellScript;
Hope this helps,