Save all case variables and set them back later

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.
mustapah
Posts: 19
Joined: Sun Jul 02, 2017 9:02 am
Country: Japan

Save all case variables and set them back later

Unread postby mustapah » Sun Aug 13, 2017 2:53 am

In the testing phase, triggers can go wrong. I want to recover case variable state before trigger execution so I don't have to create a new case for every change in trigger's code of a task. To solve the problem, I'm thinking of a simple work around: save all case variables before triggers execution, and set them back at the beginning of the task.

How can I save all case variables at once, and set them back later? Any suggestions?

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

Re: Save all case variables and set them back later

Unread postby amosbatto » Tue Aug 15, 2017 9:08 pm

First, read this about how PM stores case variables:
http://wiki.processmaker.com/3.0/Triggers#Variable_Storage
You also might want to read this:
viewtopic.php?f=47&t=713218&p=794510#p794510

You can create a table which has a backup copy of APP_DATA field. For example, if you have a PM Table named "VAR_BACKUP" with the fields APP_UID and APP_DATA:
BackupVarsPMTable.png
BackupVarsPMTable.png (32.08 KiB) Viewed 99 times


Then, use this trigger code to store the data:

Code: Select all

$caseId = @@APPLICATION;
//delete any existing records for this case in the backup table:
$sql = "DELETE FROM PMT_VAR_BACKUP WHERE APP_UID='$caseId'";
executeQuery($sql);

$sql = "INSERT INTO PMT_VAR_BACKUP (APP_UID, APP_DATA) VALUES ('$caseId', (SELECT APP_DATA FROM APPLICATION WHERE APP_UID='$caseId'))";
executeQuery($sql);


Then you can use this trigger code to later restore the APP_DATA:

Code: Select all

$caseId = @@APPLICATION;
$sql = "UPDATE APPLICATION SET APP_DATA=(SELECT APP_DATA FROM PMT_VAR_BACKUP WHERE APP_UID='$caseId') WHERE APP_UID='$caseId'";
executeQuery($sql);

Also, if you are using a recent version of PM, then you will need to edit the blacklist file so you can write to the
APPLICATION table. See: http://wiki.processmaker.com/3.0/Consulting_the_ProcessMaker_databases#Protecting_PM_Core_Tables
Amos B. Batto ♦ ProcessMaker Technical Documentation Writer & Forum Manager ♦ Cofounder of ILLA (http://www.illa-a.org)


Return to “Developing processes & programming”

Who is online

Users browsing this forum: No registered users and 1 guest