Throwaway,
You can prevent this in the future by marking the option "This a sub-process:" in the properties of the process. That way the process will not appear in the list when users go to
Home > New.
I have created a sample process that you can use to copy data from one case to another case:
(32.46 KiB) Downloaded 265 times
Here is trigger code:
Code: Select all//set to ID of Dynaform to redirect to
$dynaformId = '2408819365a307aaea160f6061114839';
$g = new G();
if (isset(@@action) and @@action == "COPY_DATA") {
if (empty(@@fromCaseNo)) {
$g->sendMessageText("Enter the case number to copy data from.", 'WARNING');
PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
if (empty(@@toCaseNo)) {
$g->sendMessageText("Enter the case number to copy data to.", 'WARNING');
PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
$sqlFrom = "SELECT * FROM APPLICATION WHERE APP_NUMBER=".@@fromCaseNo;
$sqlTo = "SELECT * FROM APPLICATION WHERE APP_NUMBER=".@@toCaseNo;
$aFromCase = executeQuery($sqlFrom);
if (!is_array($aFromCase) or count($aFromCase) != 1) {
$g->sendMessageText("Case number ".@@fromCaseNo.
" doesn't exist. Enter different 'Copy from case no.'.", 'WARNING');
PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
$aToCase = executeQuery($sqlTo);
if (!is_array($aToCase) or count($aToCase) != 1) {
$g->sendMessageText("Case number ".@@toCaseNo.
" doesn't exist. Enter different 'Copy to case no.'.", 'WARNING');
PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
$c = new Cases();
$aCaseInfoFrom =$c->LoadCase($aFromCase[1]['APP_UID']);
$aCaseInfoTo = $c->LoadCase($aToCase[1]['APP_UID']);
//unset the system variables to not copied to the other case:
$aSystemVars = array('APPLICATION', 'INDEX', 'PROCESS', 'TASK', 'APP_NUMBER', 'PIN',
'USER_LOGGED', 'ÜSR_USERNAME', 'SYS_SYS', 'SYS_LANG', 'SYS_SKIN', '__ERROR__');
$aVars = $aCaseInfoFrom['APP_DATA'];
foreach ($aSystemVars as $varName) {
unset($aVars[$varName]);
}
$aCaseInfoTo['APP_DATA'] = array_merge($aCaseInfoTo['APP_DATA'], $aVars);
$c->updateCase($aCaseInfoTo['APP_UID'], $aCaseInfoTo);
$msg = count($aVars)." variables were copied from case #".@@fromCaseNo.
" to case #".@@toCaseNo;
$g->sendMessageText($msg, 'INFO');
//reset variables:
@@action = '';
@@fromCaseNo = '';
@@toCaseNo = '';
PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
elseif (isset(@@action) and @@action == "CANCEL") {
//reset variables:
@@action = '';
@@fromCaseNo = '';
@@toCaseNo = '';
PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
And here is the JavaScript code:
Code: Select all$("#cancelButton").find("button").click(function() {
$("#action").setValue("CANCEL");
});
$("#copyCaseData").find("button").click(function() {
$("#action").setValue("COPY_DATA");
});
Create a new case and then use this process to copy the data to the new case. You can also adapt this code to use PMFNewCase() to create a new case with the case data.