osworkflow / docs / BeanShell_Functions.html

<html><head><title>OSWorkflow BeanShell Functions</title></head><body>
<ul class="star">
<li>Up to <a href="Documentation.html">Documentation</a></li>
<li>Back to <a href="Java-based_Function.html">Java-based Function</a></li>
<li>Forward to <a href="BSF_Functions.html">BSF Functions</a></li>
</ul><p class="paragraph"></p>OSWorkflow supports BeanShell as a scripting language. You can find out more about BeanShell at the <span class="nobr"></img><a href="http://www.beanshell.org/">BeanShell website</a></span>. Reading the documentation for BeanShell should be more than enough to get started with scripting for your own workflow definition file. There are a few behaviors that you should be aware of before starting, however:<p class="paragraph"></p>The <b class="bold">type</b> that must be chosen for BeanShell functions is <b class="bold">beanshell</b>. There is one required argument: <b class="bold">script</b>. The value for this argument is the actual script that is to be executed. Example:<p class="paragraph"></p><div class="wikicode"><pre>&#60;function type=<span class="java&#45;quote">"beanshell"</span>&#62;
	&#60;arg name=<span class="java&#45;quote">"script"</span>&#62;	
		<span class="java&#45;object">System</span>.out.println(<span class="java&#45;quote">"Hello, World!"</span>);
	&#60;/arg&#62;
&#60;/function&#62;</pre></div><p class="paragraph"></p>There are three variables in the expression scope at all times: <i class="italic">entry</i> <i class="italic">context</i>, and <i class="italic">store</i>. The variable "entry" is an object that implements <i class="italic">com.opensymphony.workflow.spi.WorkflowEntry</i> and represents the workflow instance. The variable "context" is an object of type <i class="italic">com.opensymphony.workflow.WorkflowContext</i> which allows for BeanShell functions to roll back transactions or determine the caller name. The "store" variable is of type <i class="italic">com.opensymphony.workflow.WorkflowStore</i>
 and allows the function to access the underlying workflow persistence store.<p class="paragraph"></p>Just like OSWorkflow Java Function, there are three variables that can be used and are automatically set in the BeanShell scope: <b class="bold">transientVars</b>, <b class="bold">args</b>, and <b class="bold">propertySet</b>. The same rules that apply to Java functions also apply here. Example:<p class="paragraph"></p><div class="wikicode"><pre>&#60;function type=<span class="java&#45;quote">"beanshell"</span>&#62;
	&#60;arg name=<span class="java&#45;quote">"script"</span>&#62;	
		propertySet.setString(<span class="java&#45;quote">"world"</span>, <span class="java&#45;quote">"Earth"</span>);
	&#60;/arg&#62;
&#60;/function&#62;
&#60;function type=<span class="java&#45;quote">"beanshell"</span>&#62;
	&#60;arg name=<span class="java&#45;quote">"script"</span>&#62;	
		<span class="java&#45;object">System</span>.out.println(<span class="java&#45;quote">"Hello, "</span>+propertySet.getString(<span class="java&#45;quote">"world"</span>));
	&#60;/arg&#62;
&#60;/function&#62;</pre></div><p class="paragraph"></p>The output of these two scripts would be "Hello, Earth". This is because any variable stored in the <b class="bold">propertySet</b> is persisted for use in functions later in the workflow.<p class="paragraph"></p></body></html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.