Adding extra fields to Report Tables

From pmusers
Jump to: navigation, search

The easiest way to capture information about cases and export it to a Report Table is to create variables in the process. Then, add triggers to save values in those variables.

For example, to get the title of the current task in the case and the name of the user who is working on the case, create the "currentUser" and "currentTask" variables in the process:

AddingFieldsReportTables CreateVariables.png


Then, create the following trigger to get the name of the current assigned user and the current task and save that information in the @@currentUser and @@currentTask variables:

$aUser = userInfo(@@USER_LOGGED);
@@currentUser = $aUser['firstname'].' '.$aUser['lastname'];

$t = new Task();
$aTask = $t->Load(@@TASK);
@@currentTask = $aTask['TAS_TITLE'];

AddFieldsReportTables CreateTrigger.png


Then, set the above trigger to fire before the first step in every task in the process:

AddFieldsReportTables SetTrigger.png


Finally, create a Report Table that contains the "currentUser" and "currentTask" variables:

AddFieldsReportTables CreateReportTable.png


When cases are run, the Report Table will contain the fields CURRENTUSER and CURRENTTASK:

AddFieldsReportTables ExportedData.png

Adding extra fields in the source code

There is a second way to add additional fields with information about cases in a Report Table, but it is not recommended, since it involves changing the ProcessMaker source code.

First, edit the file workflow/engine/src/ProcessMaker/BusinessModel/ReportTable.php and change the source code starting at line 55 from:

$application = new \stdClass(); //APP_STATUS
        $application->uid = '';
        $application->field_dyn = '';
        $application->field_uid = '';
        $application->field_name = 'APP_STATUS';
        $application->field_label = 'APP_STATUS';
        $application->field_type = 'VARCHAR';
        $application->field_size = 10;
        $application->field_dyn = '';
        $application->field_key = 0;
        $application->field_null = 0;
        $application->field_filter = false;
        $application->field_autoincrement = false;
        array_push($defaultColumns, $application);        

        //If it is a grid report table
        if ($type == 'GRID') {

To:

$application = new \stdClass(); //APP_STATUS
        $application->uid = '';
        $application->field_dyn = '';
        $application->field_uid = '';
        $application->field_name = 'APP_STATUS';
        $application->field_label = 'APP_STATUS';
        $application->field_type = 'VARCHAR';
        $application->field_size = 10;
        $application->field_dyn = '';
        $application->field_key = 0;
        $application->field_null = 0;
        $application->field_filter = false;
        $application->field_autoincrement = false;
        array_push($defaultColumns, $application);
        
        $application = new \stdClass(); //DEL_INDEX
        $application->uid = '';
        $application->field_dyn = '';
        $application->field_uid = '';
        $application->field_name = 'DEL_INDEX';
        $application->field_label = 'DEL_INDEX';
        $application->field_type = 'INTEGER';
        $application->field_size = 11;
        $application->field_dyn = '';
        $application->field_key = 0;
        $application->field_null = 0;
        $application->field_filter = false;
        $application->field_autoincrement = false;
        array_push($defaultColumns, $application);
        
        $application = new \stdClass(); //TASK_UID
        $application->uid = '';
        $application->field_dyn = '';
        $application->field_uid = '';
        $application->field_name = 'TASK_UID';
        $application->field_label = 'TASK_UID';
        $application->field_type = 'VARCHAR';
        $application->field_size = 32;
        $application->field_dyn = '';
        $application->field_key = 0;
        $application->field_null = 0;
        $application->field_filter = false;
        $application->field_autoincrement = false;
        array_push($defaultColumns, $application);


        //If it is a grid report table
        if ($type == 'GRID') {

In the same file, change line 402 from:

                    if (!preg_match('/^(?:APP_UID|APP_NUMBER|APP_STATUS|ROW)$/', $column->field_name)) {

To:

                    if (!preg_match('/^(?:APP_UID|APP_NUMBER|APP_STATUS|DEL_INDEX|TASK_UID|ROW)$/', $column->field_name)) {

Also change line 674 from:

        $defaults = ["APP_UID", "APP_NUMBER", "APP_STATUS"];

To:

        $defaults = ["APP_UID", "APP_NUMBER", "APP_STATUS", "DEL_INDEX", "TASK_UID"];

Second, edit the file workflow/engine/classes/Cases.php in version 3.2.2 and later (or workflow/engine/classes/class.cases.php in version 3.2.1 or earlier) and change the code starting at line 978 from:

            $additionalTables->updateReportTables(
                    $appFields['PRO_UID'], $appUid, $Fields['APP_NUMBER'], $appData, $Fields['APP_STATUS'] 
            );

To:

            $delIndex = isset($Fields['DEL_INDEX']) ? trim($Fields['DEL_INDEX']) : 0;
            $tasUid = isset($Fields['TAS_UID']) ? trim($Fields['TAS_UID']) : '';

            $reportTables->updateTables($appFields['PRO_UID'], $appUid, $Fields['APP_NUMBER'], $appData);
            $additionalTables->updateReportTables(
                    $appFields['PRO_UID'], $appUid, $Fields['APP_NUMBER'], $appData, $Fields['APP_STATUS'], $delIndex, $tasUid 
            );

Third, edit the file workflow/engine/classes/model/AdditionalTables.php and change the code starting at line 880 from:

     * @param string $caseData
     */
    public function updateReportTables($proUid, $appUid, $appNumber, $caseData, $appStatus)

to:

     * @param string $caseData
     * @param int $delIndex
     * @param string $taskUid
     */
    public function updateReportTables($proUid, $appUid, $appNumber, $caseData, $appStatus, $delIndex=0, $taskUid='')

In the same file, change the code starting at line 952 from:

                    if (is_array($records) && count($records) > 0) {
                        // if the record already exists on the report table
                        foreach ($records as $record) {
                            //update all records
                            if (method_exists($record, 'setAppStatus')) {
                                $record->setAppStatus($appStatus);
                            }
                            $record->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                            if ($record->validate()) {
                                $record->save();
                            }
                        }
                    } else {
                        // there are not any record for this application on the table, then create it
                        eval('$obj = new ' . $className . '();');
                        $obj->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                        $obj->setAppUid($appUid);
                        $obj->setAppNumber($appNumber);
                        if (method_exists($obj, 'setAppStatus')) {
                            $obj->setAppStatus($appStatus);
                        }
                        $obj->save();
                    }

To:

                    if (is_array($records) && count($records) > 0) {
                        // if the record already exists on the report table
                        foreach ($records as $record) {
                            //update all records
                            if (method_exists($record, 'setAppStatus')) {
                                $record->setAppStatus($appStatus);
                            }
                            if (method_exists($record, 'setDelIndex')) {
                                $record->setDelIndex($delIndex);
                            }
                            if (method_exists($record, 'setTaskUid')) {
                                $record->setTaskUid($taskUid);
                            }
                            $record->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                            if ($record->validate()) {
                                $record->save();
                            }
                        }
                    } else {
                        // there are not any record for this application on the table, then create it
                        eval('$obj = new ' . $className . '();');
                        $obj->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME);
                        $obj->setAppUid($appUid);
                        $obj->setAppNumber($appNumber);
                        if (method_exists($obj, 'setAppStatus')) {
                            $obj->setAppStatus($appStatus);
                        }
                        if (method_exists($obj, 'setDelIndex')) {
                            $obj->setDelIndex($delIndex);
                        }
                        if (method_exists($obj, 'setTaskUid')) {
                            $obj->setTaskUid($taskUid);
                        }
                        $obj->save();
                    }


After making those changes, the current delegation index and ID of the current task should be exported to the Report Table:

AddFieldsReportTables InPhpMyAdmin.png