diff --git a/workflow/engine/classes/Cases.php b/workflow/engine/classes/Cases.php index 6204f0b38..1b06cdc58 100644 --- a/workflow/engine/classes/Cases.php +++ b/workflow/engine/classes/Cases.php @@ -3539,17 +3539,19 @@ class Cases $varsChanged = $oPMScript->getVarsChanged(); $appDataAfterTrigger = $oPMScript->aFields; - //Get the key and values changed + //Get the key and values changed only if the variable has the prefix + //@see https://wiki.processmaker.com/3.2/Triggers#Typing_rules_for_Case_Variables $fieldsTrigger = $this->findKeysAndValues($appDataAfterTrigger, $varsChanged); - //We will be load the last appData - if ($oPMScript->executedOn() === $oPMScript::AFTER_ROUTING) { - $appUid = !empty($fieldsCase['APPLICATION']) ? $fieldsCase['APPLICATION'] : ''; - if (!empty($appUid)) { - //Update $fieldsCase with the last appData - $fieldsCase = $this->loadCase($appUid)['APP_DATA']; - } + + //We will be load the last appData because: + //Other execution can be changed the variables or Plugin or PMFunction + $appUid = !empty($fieldsCase['APPLICATION']) ? $fieldsCase['APPLICATION'] : ''; + if (!empty($appUid)) { + //Update $fieldsCase with the last appData + $fieldsCase = $this->loadCase($appUid)['APP_DATA']; } + //Merge the current appData with variables changed $fieldsCase = array_merge($fieldsCase, $fieldsTrigger); diff --git a/workflow/engine/classes/class.pmScript.php b/workflow/engine/classes/class.pmScript.php index 19158ae00..8b2d2a643 100644 --- a/workflow/engine/classes/class.pmScript.php +++ b/workflow/engine/classes/class.pmScript.php @@ -464,6 +464,8 @@ class PMScript $sScript = "try {\n" . $sScript . "\n} catch (Exception \$oException) {\n " . " \$this->aFields['__ERROR__'] = utf8_encode(\$oException->getMessage());\n}"; $this->executeAndCatchErrors($sScript, $this->sScript); + //We get the affected_fields only if has the prefix + //@see https://wiki.processmaker.com/3.2/Triggers#Typing_rules_for_Case_Variables $this->setVarsChanged($this->affected_fields); $this->aFields["__VAR_CHANGED__"] = implode(",", $this->affected_fields); for ($i = 0; $i < count($this->affected_fields); $i ++) {