Executing trigger before subprocess case

From pmusers
Jump to: navigation, search

A subprocess may not start with a script task. All processes must start with a task which is assigned to a user.

If needing to execute a trigger when a subprocess case starts, then right click on a blank area of the subprocess and select Edit Process in the context menu that appears. In the "Edit process" dialog box that appears, select a trigger in the Execute a trigger when a case is created: dropdown box.

SetTriggerWhenCaseCreated.png

This trigger will be executed when the subprocess case is created.

Normally, information about the parent case can be obtained in the subprocess case by querying the SUB_APPLICATION table in the database. Then the Cases::LoadCase() function can used to lookup information from the parent case. In the following trigger in the subprocess, the clientName variable is copied from the parent case:

$subcaseId = @@APPLICATION;
$sql = "SELECT * FROM SUB_APPLICATION WHERE APP_UID='$subcaseId'";
$aCase = executeQuery($sql);
$parentCaseId = $aCase[1]['APP_PARENT'];

$oCase = new Cases();
$aParentCaseInfo = $oCase->loadCase($parentCaseId);

//get a case variable from the parent case:
$client = $aParentCaseInfo['APP_DATA']['clientName'];

Unfortunately, if a trigger is fired before the subprocess case is created, then the variables from parent case have not yet been transferred to the subprocess case and there is not yet a database record for the subprocess case in the SUB_APPLICATION, APPLICATION, APP_DELEGATION and APP_CACHE_VIEW tables, so information about the new subprocess case can't be looked up in the database.

If a trigger is fired when the subprocess case is created, the @@APPLICATION system variable is set to the ID of the new subprocess case, but the $_SESSION['APPLICATION'] is still set to the ID of the parent case. Therefore, the following trigger needs to be used instead of the above trigger to copy the clientName variable from the parent case:

$subcaseId = @@APPLICATION;
$parentCaseId = $_SESSION["APPLICATION"];

$oCase = new Cases();
$aCaseInfo = $oCase->loadCase($parentCaseId);

//get a variable from the parent case:
@@clientName3 = $aCaseInfo['APP_DATA']['clientName'];