You can manually create a
PM Table where you keep track of this information for each user.
Then, you can use
executeQuery() in a trigger to retrieve the information to display in the form.
For example, if your PM Table is named "USERS_DAYS_OFF" and it contains the fields:
- USERNAME
- DAYS_AVAILABLE
- DAYS_REQUESTED
- DAYS_RESTED
And you have the following associated variables for the fields in your DynaForm:
- daysAvailable
- daysRequested
- daysRested
Then, create the following trigger which is
set to execute before the DynaForm:
Code: Select all$username = @@USR_USERNAME; //username of the current logged-in user
$sql = "SELECT DAYS_AVAILABLE, DAYS_REQUESTED, DAYS_RESTED
FROM PMT_USERS_DAYS_OFF WHERE USERNAME='$username'";
$result = executeQuery($sql);
if (empty($result)) {
throw new Exception("There is no record in the PMT_USERS_DAYS_OFF table for '$username'.");
}
@@daysAvailable = $result[1]['DAYS_AVAILABLE'];
@@daysRequested = $result[1]['DAYS_REQUESTED'];
@@daysRested = $result[1]['DAYS_RESTED'];
Then, you can create another trigger which is executed after the DynaForm which updates the PM Table based on what is entered in the DynaForm:
Code: Select all$available = (int) @@daysAvailable;
$requested = (int) @@daysRequested;
$rested = (int) @@daysRested;
$username = @@USR_USERNAME;
$sql = "UPDATE PMT_USERS_DAYS_OFF SET DAYS_AVAILABLE='$available',
DAYS_REQUESTED='$requested', DAYS_RESTED='$rested'
WHERE USERNAME='$username'";
@@ret = $executeQuery($sql);
PS: If you want to calculate days and hours, based on a configured calendar in ProcessMaker, see the
ExtraFunctions plugin.