Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By Skipper
#796199
Hello,

is it possible to implement a function in a case to start a new case with the same variable values as an old completed case?

Thanks
Kind regards.
User avatar
By amosbatto
#798779
If you want to clone a case which starts from the same task as the existing case, then you can use this process:
viewtopic.php?f=44&t=713336&p=795791#p795791

If you want to create a new case that begins in the starting task but has the same values as an existing case, then you can use this process:
(28.5 KiB) Downloaded 386 times
Here is the trigger code that it uses:
Code: Select all
//set to ID of form where user selects case to copy:
$dynaformId = '3633777765a134ed6299f98068921314';

$g = new G();
if (empty(@@selectCase)) {
    $g->SendMessageText("Please enter the number of the case whose values should be copied.",
                        'WARNING');
    PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}    
    
$caseNo = @@selectCase;
$sql = "SELECT APP_UID, PRO_UID, TAS_UID, USR_UID, APP_TAS_TITLE, APP_PRO_TITLE
    FROM APP_CACHE_VIEW 
    WHERE APP_NUMBER='$caseNo' AND DEL_INDEX=1";
$aResult = executeQuery($sql);
    
if (!is_array($aResult) or count($aResult) == 0) {
    $g->SendMessageText("Unable to find case number $caseNo in the APP_CACHE_VIEW table.", 
                        'ERROR');
    PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}

$caseId = $aResult[1]['APP_UID'];
$oCase = new Cases();
$aCase = $oCase->LoadCase($caseId);

//delete system variables from old case before copying to the new case:
$aSystemVars = array('SYS_SYS', 'SYS_SKIN', 'SYS_LANG', 'APPLICATION', 'APP_NUMBER', 
    'PROCESS', 'USER_LOGGED', 'USR_USERNAME', 'TASK', 'INDEX', 'PIN');
    
foreach ($aSystemVars as $var) {
    unset($aCase['APP_DATA'][$var]);
}
    
$newCaseId = PMFNewCase($aResult[1]['PRO_UID'], $aResult[1]['USR_UID'],
                        $aResult[1]['TAS_UID'], $aCase['APP_DATA']);

if (!empty($newCaseId)) {
    $aCase = $oCase->LoadCase($newCaseId, 1);
    $g->SendMessageText(
        "New case {$aCase['APP_TITLE']} created in {$aResult[1]['APP_PRO_TITLE']} / ".
        "{$aResult[1]['APP_TAS_TITLE']} and assigned to {$aCase['CURRENT_USER']}.", 'INFO');
    PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}
else {
    $g->SendMessageText("Unable to create new case" . 
        (isset(@@__ERROR__) ? ":\n". @@__ERROR__ : ''), 'ERROR');
    PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
}

 
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]