Tips & Tricks - Start processes
This article shows different ways to start processes, including via Groovy with simultaneous parameter passing. To make all the above settings accessible, please enable expert options in the corresponding modules.
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 figure 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 de.uplanet.lucy.server.workflow.eventhandler.UserWorkflowEventHandler class 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 class "JobStarter". 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 parameters "testParam" and "greeting" 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 each time with the current GUID of the timer you want to start. Our sample process, we use 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 script condition
The Groovy condition checks if 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 upper left section (1).
2. Trigger event
The process can now be started via the context menu "Trigger this event now" in the generic event handler.
You will find the results in the process log file afterwards.
Start the process via a task
To execute a process as a subsequent job, the process requires a Generic event handler. In the properties dialog of the event handler select the class "de.uplanet.lucy.server.workflow.eventhandler.UserWorkflowEventHandler" on the "Generic event handler" tab. The automatically created parameter "eventGuid" has a GUID as its value. Copy the GUID to the clipboard or save it somewhere else (e.g. a text editor) so that it can be used easily later on. 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.
Using the GUID defined in the generic event handler, the process can now be started from the task scheduler, which you can find in the "Tools" module.
Select any task from the list. Select "Edit schedule" from the context menu to open the "Subsequent jobs" tab. Enter the eventGuid from the Generic event handler 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
Processes can be triggered after a Data transfer in the "Integration" module. Open the properties dialog of an existing data transfer and switch to the "Subsequent jobs" tab. Enter the eventGuid from the Generic event handler 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 as follows via JavaScript:
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.