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.
By Skipper

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?

Kind regards.
By amosbatto
If you want to clone a case which starts from the same task as the existing case, then you can use this process:

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 13 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.",
    PMFRedirectToStep(@@APPLICATION, @%INDEX, 'DYNAFORM', $dynaformId);
$caseNo = @@selectCase;
$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.", 
    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', 
foreach ($aSystemVars as $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);
        "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);

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

ProcessMaker hanging after i change item in proces[…]

I want all users to be able to start a process/cas[…]

I dont think so because the database is on the sa[…]

I don't have MSSQL installed to test this, but I i[…]