NAlvarado wrote:I have a script task that checks a PM table (custom) that have a status of NEW. I also have another script task that I'm going to place into a sub-process (has 2 script tasks). If the main process finds records in the PM table then I want to pass each row found to the sub-process to perform the next steps. Is there a way to do a loop in the main process to pass the invoiceID, originator (values from the PM table) from the main process to the sub process?
The easiest way to pass variables from the parent case to a subprocess case is to pass variables when creating the subprocess case. You can pass a array, if you want to send multiple values in one variable. For example:
Code: Select all@=invoiceIds = array();
@=originators = array();
$records = executeQuery("SELECT INVOICE_ID, ORIGINATOR FROM PMT_MY_TABLE");
foreach ($records as $record) {
@=invoiceIds[] = $record['INVOICE_ID'];
@=originators[] = $record['ORIGINATOR'];
}
Now, the array variables @=invoiceIds and @=originators can be passed to the subprocess case when it is created.
If the subprocess case already exists and the subprocess is asynchronous so the parent case and subprocess case are both running at the same time, then you use the following trigger to pass data from the parent case to the asynchronous subprocess case:
Code: Select all//lookup subprocess case in the database:
$parentCaseId = @@APPLICATION;
$cases = executeQuery("SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$parentCaseId'");
if (!empty($cases)) {
$subcaseId = $cases[1]['APP_UID'];
//send array variables to subprocess case:
$aVars = array(
'invoiceIds' => @=invoiceIds,
'originators' => @=originators
);
PMFSendVariables($subcaseId, $aVars);
}
In the subprocess, you can add a trigger to check if the variables have arrived:
Code: Select allif (isset(@=invoiceIds)) {
for ($i = 0; $i < count(@=invoiceIds); $i++) {
$invoiceId = @=invoiceId[i];
$originator = @=originators[i];
//do something with data
}
}
If you want to execute a loop for the number of records found in the PM Table, then see:
https://wiki.processmaker.com/3.2/Trigg ... r_of_Times
NAlvarado wrote:s it basically calling PMFNewCase within the main script task to call the task in the sub-process?
There is no function in ProcessMaker to create subprocess cases. If you use PMFNewCase() it will create normal new cases, but not subprocess cases.
NAlvarado wrote:If there is another script task after the first script task in the sub-process, will it also call that task?
Subprocesses can't start with script tasks. You have to start the subprocess with a normal task, then you can have multiple script tasks in a series.