Support for Scripts in Business Process

With support for scripting and the dynamic process definition, it is possible to declare not only the structure of the business process but also to define the behavior directly in the xml which defines the process.

Calling a Script

Here is an example of a process definition with a script that returns the next transition:

<?xml version='1.0' encoding='utf-8'?>
<process xmlns='http://www.hybris.de/xsd/processdefinition' start='action0' name='testProcessDefinition'>
	<scriptAction id='action0'>
		<script type='javascript'>(function() { return 'itworks' })()</script>
		<transition name='itworks' to='success'/>
	</scriptAction>
	<end id='success' state='SUCCEEDED'>Everything was fine</end>
</process>

This simple process definition shows the usage of a scriptAction element. It is almost exactly the same as an action element, but instead of executing some logic from a spring bean, it executes the script defined in a script element. Here it only invokes an anonymous function that returns the next transition ('itworks').

Accessing a Business Process Context from a Script

Scripts from process definitions are invoked with a special process parameter passed to the script.The process parameter is an instance of the BusinessProcessModel describing the running business process. Here is an example of script that modifies a context parameter of a business process:

<?xml version='1.0' encoding='utf-8'?>
<process xmlns='http://www.hybris.de/xsd/processdefinition' start='action0' name='testProcessDefinition'>
<contextParameter name='testParameter' use='required' type='java.lang.String'/>
	<scriptAction id='action0'>
		<script type='javascript'>
			var parameter = process.contextParameters.get(0);
			parameter.setValue('changedFromScript');
			modelService.save(parameter);
			'itworks'
		</script>
		<transition name='itworks' to='success'/>
	</scriptAction>
	<end id='success' state='SUCCEEDED'>Everything was fine</end>
</process>