new Case with same values

Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

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.
Skipper
Posts: 6
Joined: Thu Dec 08, 2016 8:32 am
Country: Germany

new Case with same values

Unread postby Skipper » Mon Nov 20, 2017 5:20 am

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.

amosbatto
Posts: 5564
Joined: Mon Jun 22, 2009 10:28 am
Country: Bolivia
Location: La Paz

Re: new Case with same values

Unread postby amosbatto » Mon Nov 20, 2017 7:31 pm

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:
New_case_with_copied_data-1.pmx
(28.5 KiB) Downloaded 2 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($newCaseId1);
    
$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);
}

 
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)

Skipper
Posts: 6
Joined: Thu Dec 08, 2016 8:32 am
Country: Germany

Re: new Case with same values

Unread postby Skipper » Wed Nov 22, 2017 6:09 am

Thank you very much.
This was exactly what I need.
I have modified it a bit but it's the solution.


Return to “Developing processes & programming”

Who is online

Users browsing this forum: No registered users and 2 guests