This is a old topic, I know but I am going to post my findings below.
This script below will insert multiple subprocess cases, as asynchronous (Not Synchronous - Which means variables will not be passed back into the main case)
It loops through a GRID to determine how many sub cases to create. It creates them with PMFNewCase and then updates the correct databases, so stuff does not get out of sync.
*** PROCESSMAKER Support told me that its not do-able and highly suggests not to modify the processmaker database from triggers. But I went and figured it out on my own.
*** Also this may not be complete and may break counts and such, but so far I have not had any issues.
### THIS SCRIPT IS MADE FOR PROCESSMAKER 3.0.1.X (Specifically I am using on 3.0.1.7) ###
*** The webentry users is because I am using the WebEntry feature on the start task and for Actions By Email, you can use a real user in its place.
The Basic steps are
1. PMFNewCase (Create the case)
2. Update Tables "APPLICATION", "LIST_INBOX", "LIST_PARTICIPATED_LAST" and set the APP_STATUS column to "TO_DO".
3. INSERT INTO Table "SUB_APPLICATION"
4. INSERT INTO Table "LIST_MY_INBOX"
5. UPDATE USER CASES COUNT on USERS Table
*** Again this may not be the correct process of doing this, but its working for me... Enjoy
Code: Select all// Get the Process UID
$getSubProcessUID = "SELECT PRJ_UID FROM BPMN_PROJECT WHERE PRJ_NAME LIKE 'QFL Supervisor SubProcess'";
$results = executeQuery($getSubProcessUID);
$subprocessUID = $results[1]['PRJ_UID'];
// Get the User UID for WebEntry
$getWebEntryUserUID = "SELECT USR_UID FROM USERS WHERE USR_USERNAME LIKE 'webentry'";
$results = executeQuery($getWebEntryUserUID);
$subprocessUserUID = $results[1]['USR_UID'];
// Get the Task UID of the first task on the subprocess
$getSubProcessFirstTaskUID = "SELECT TAS_UID FROM TASK WHERE PRO_UID = '$subprocessUID' AND TAS_START='TRUE'";
$results = executeQuery($getSubProcessFirstTaskUID);
$subprocessFirstTaskUID = $results[1]['TAS_UID'];
// TODO CHANGE subSupervisorEmail
$aFields = array(
'deleteMeLater' => 'Yay it worked!',
'subSupervisorEmail' => 'EMAILHERE'
);
// Serialize object because processmaker is lame
// This serilized object needs to be inserted into the SUB_APPLICATION table.
$aFieldsSerialized = serialize($aFields);
$callcenterArray = array('fpi','ost','rsc','techsupport');
if (@@FeedbackDepartment == 'people') {
foreach(@@AssociatedEmployeeGrid as $row) {
if (!in_array($row['empChannel'], $callcenterArray)) {
// Create Case for Row
$caseUIDReturn = PMFNewCase($subprocessUID, $subprocessUserUID, $subprocessFirstTaskUID, $aFields);
// PMFNEWCASE RETURNS 0 ON ERROR
if ($caseUIDReturn) {
$thisAppID = @@APPLICATION;
// Move from draft, to inbox!
executeQuery("UPDATE APPLICATION SET APP_STATUS='TO_DO', APP_PARENT='$thisAppID' WHERE APP_UID='$caseUIDReturn'");
$currentDateTime = date("Y-m-d H:i:s");
// Insert into the SUB_APPLICATION TABLE
executeQuery("INSERT INTO SUB_APPLICATION (
APP_UID, APP_PARENT, DEL_INDEX_PARENT,
DEL_THREAD_PARENT, SA_STATUS, SA_VALUES_OUT,
SA_INIT_DATE, SA_FINISH_DATE
) VALUES (
'$caseUIDReturn', '$thisAppID', '4',
'1', 'FINISHED', '$aFieldsSerialized',
'$currentDateTime', '$currentDateTime')");
// UPDATE LIST_INBOX COLUMN APP_STATUS
executeQuery("UPDATE LIST_INBOX SET APP_STATUS='TO_DO' WHERE APP_UID='$caseUIDReturn'");
// No Update to LIST_PARTICIPATED_HISTORY
// UPDATE LIST_PARTICIPATED_LAST COLUMN APP_STATUS
executeQuery("UPDATE LIST_PARTICIPATED_LAST SET APP_STATUS='TO_DO' WHERE APP_UID='$caseUIDReturn'");
// NO UPDATE APP_CACHE_VIEW
// INSERT INTO LIST_MY_INBOX
//// First get info from list inbox
$listInboxReturn = executeQuery("SELECT * FROM LIST_INBOX WHERE APP_UID='$caseUIDReturn'");
//// Now lets do the insert
executeQuery("
INSERT INTO LIST_MY_INBOX
(APP_UID, USR_UID, TAS_UID, PRO_UID, APP_NUMBER,
APP_TITLE, APP_PRO_TITLE, APP_TAS_TITLE, APP_CREATE_DATE, APP_UPDATE_DATE,
APP_STATUS, DEL_INDEX, DEL_PREVIOUS_USR_UID, DEL_PREVIOUS_USR_USERNAME, DEL_PREVIOUS_USR_FIRSTNAME,
DEL_PREVIOUS_USR_LASTNAME, DEL_CURRENT_USR_UID, DEL_CURRENT_USR_USERNAME, DEL_CURRENT_USR_FIRSTNAME,
DEL_CURRENT_USR_LASTNAME, DEL_DELEGATE_DATE, DEL_INIT_DATE, DEL_DUE_DATE, DEL_PRIORITY)
VALUES
('$caseUIDReturn', '$subprocessUserUID', '$subprocessFirstTaskUID', '{$listInboxReturn[1]['PRO_UID']}',
'{$listInboxReturn[1]['APP_NUMBER']}', '{$listInboxReturn[1]['APP_TITLE']}', '{$listInboxReturn[1]['APP_PRO_TITLE']}',
'{$listInboxReturn[1]['APP_TAS_TITLE']}', '$currentDateTime', '{$listInboxReturn[1]['APP_UPDATE_DATE']}',
'TO_DO', '{$listInboxReturn[1]['DEL_INDEX']}', '{$listInboxReturn[1]['DEL_PREVIOUS_USR_UID']}', '{$listInboxReturn[1]['DEL_PREVIOUS_USR_USERNAME']}',
'{$listInboxReturn[1]['DEL_PREVIOUS_USR_FIRSTNAME']}', '{$listInboxReturn[1]['DEL_PREVIOUS_USR_LASTNAME']}', '$subprocessUserUID',
'webentry', 'WebEntry', 'WebEntry',
'{$listInboxReturn[1]['DEL_DELEGATE_DATE']}', '{$listInboxReturn[1]['DEL_INIT_DATE']}', '{$listInboxReturn[1]['DEL_DUE_DATE']}',
'{$listInboxReturn[1]['DEL_PRIORITY']}')
");
// Need to update User Cases Counts...
//// Lets first select the current counts out of the DB
$userTableCounts = executeQuery("SELECT USR_TOTAL_INBOX, USR_TOTAL_DRAFT FROM USERS WHERE USR_UID='$subprocessUserUID'");
//// Now Lets update them
$newUserInboxCount = $userTableCounts[1]['USR_TOTAL_INBOX'] + 1;
$newUserDraftCount = $userTableCounts[1]['USR_TOTAL_DRAFT'] - 1;
executeQuery("UPDATE USERS SET USR_TOTAL_INBOX = '$newUserInboxCount', USR_TOTAL_DRAFT='$newUserDraftCount' WHERE USR_UID='$subprocessUserUID'");
} else {
@@CASE_NOT_CREATED += 'Case Not Created for ' . $row['empName'] . '. -|- ';
}
}
}
}