Tips & Tricks - Starting processes
This article shows different ways to start processes, including via Groovy with simultaneous parameter passing. Please activate expert options in the corresponding modules so that all the settings mentioned can be accessed.
Starting timers via Groovy and passing parameters
Timers in processes can be started via Groovy. Parameters can also be passed in the process. You can download our sample process here and import it as usual. In the illustration below you can see the process opened in the "Processes" module.
Process structure
1. Generic event handler with / without parameters
In the properties dialog of these two generic event handlers, you can see that the class "de.uplanet.lucy.server.workflow.eventhandler.UserWorkflowEventHandler" is selected. The eventGuid is automatically assigned and entered as a property when this class is selected. With this configuration, the timer (3) included in the process can be started. You will learn how to do this after the process elements have been described.
2. Groovy action with / without parameters
The two Groovy actions contain script to start the timer optionally with or without passing parameters at the same time. This function returns the "JobStarter" class. The script for the Groovy action "With parameters" looks like this:
import de.uplanet.lucy.server.scheduler.JobStarter
JobStarter.startJob("<Timer-GUID>", [testParam: true, greeting: ' Hello world!'])
The "testParam" and "greeting" parameters are available in the SharedState when the process has been started.
Here is the script for the Groovy action "Without parameters" :
import de.uplanet.lucy.server.scheduler.JobStarter
JobStarter.startJob("<Timer-GUID>")
Replace <Timer-GUID> in the script with the current GUID of the timer you want to start. In our example process, it is the timer GUID "B39F3AA1C06E56FD06538F92F46C075333F97F68".
3. Timer
This timer is to be started.
4. Timer event handler
The timer event handler is connected to the timer and is triggered when the timer is started.
3. Groovy condition
The Groovy condition checks whether there are parameters. It contains the following script:
println(g_sharedState)
return g_sharedState.testParam ? with_params : without_params
In the first line, the SharedState is written to the process logfile.
The second line branches to the corresponding following Groovy action depending on the result.
4. With parameters / 5. Without parameters
The Groovy actions write the result into the process log file.
println("With parameters.")
println(g_sharedState.greeting)
println("Without parameters.")
println(g_sharedState)
Start process
1. Activate process
If the process is still deactivated, activate it by clicking in the top left-hand area (1).
2. Trigger event
The process can now be started via the "Trigger this event now" context menu of the generic event handler.
You will then find the result in the process log file.
Start the process via a task
To execute a process as a follow-up order, a generic event handler is required in the process. In the properties dialog of the generic event handler, the class "de.uplanet.lucy.server.workflow.eventhandler.UserWorkflowEventHandler" must be selected on the "Generic event handler" tab. The automatically created parameter "eventGuid" has a GUID as its value. Copy this GUID to the clipboard or save it in another location for later use (e.g. in a text editor). Additional process elements can be connected to the Generic event handler as usual.
When using a generic event handler there is no direct relationship to a data group. Thus you have no dynamic data records available, for example.
The process can now be started from the task scheduler, which you can find in the "Tools" module, using the GUID defined in the generic event handler.
Select any task from the list. You can access the "Follow-up orders" tab via the "Edit schedule" context menu. The eventGuid of the generic event handler can be entered there in the "Process event GUID" field. This means the process will start as soon as the task has been performed.
Start the process via a data transfer
In the "Integration" module, processes can be started following a data transfer. To do this, open the properties dialog of an existing data transfer and switch to the "Follow-up orders" tab. The eventGuid of the generic event handler can be entered there in the "Process event GUID" field. This means the process will start as soon as the data transfer has been performed.
Start the process via a JavaScript
A process can also be started via JavaScript as follows:
function prozess_start()
{
triggerUserWorkflowEvent("GUID");
}
The function ""triggerUserWorkflowEvent()"" triggers the process. This function requires the eventGuid of the corresponding generic event handler.
You can identify the GUID by selecting the generic event handler in the process and then pressing F4.