Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By NAlvarado
#816202
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? Is it basically calling PMFNewCase within the main script task to call the task in the sub-process? If there is another script task after the first script task in the sub-process, will it also call that task?
User avatar
By amosbatto
#816205
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 all
if (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.
#816266
I have not created the subprocess yet. The 2 scripts that exist in the WF I want to place into a subprocess. I'm trying to understand the logic. If I am passing array variables from the parent to the sub, then the variables in the sub will also be array type?

If a subprocess needs a starting task because a script task can't be the first one, do I place the trigger for the variables ot pass to the script in the first dummy task of the subprocess?
#816268
NAlvarado wrote:I have not created the subprocess yet. The 2 scripts that exist in the WF I want to place into a subprocess. I'm trying to understand the logic. If I am passing array variables from the parent to the sub, then the variables in the sub will also be array type?
The variable type will not be changed when passing the variable to the subprocess.
NAlvarado wrote: If a subprocess needs a starting task because a script task can't be the first one, do I place the trigger for the variables ot pass to the script in the first dummy task of the subprocess?
You can set the trigger to fire when the subprocess case is created. There is an option in the process properties in PM 3.2 and later for that. You can also use a dummy task, but it won't execute the trigger without the user opening the case.

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]