- Created by Rodney Harper, last modified by Juan Carlos Yujra on Oct 06, 2017
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 33 Next »
Overview
This document is intended to explain the most common triggers and JavaScript code that we usually use in a proof of concept.
Triggers (PHP)
Case Link
It makes possible to open a case inside ProcessMaker using only a link. This link is stored in a variable and then used to send in a notification.
@@app_link = PMFCaseLink(@@APPLICATION, @@SYS_SYS, @@SYS_LANG, @@SYS_SKIN);
Server Info
Trigger to get the server url.
$httpServer = (isset($_SERVER['HTTPS'])) ? 'https://' : 'http://'; @@SERVER = $httpServer.$_SERVER['HTTP_HOST'];
Company Logo
The logo/image is added to ProcessMaker's public files. Then it is created a link to get the image and it is stored in a PM variable. This variable is used in a form and a notification.
$logo = $httpServer.$_SERVER['HTTP_HOST']."/sys".SYS_SYS."/".SYS_LANG."/".SYS_SKIN."/".@@PROCESS."/logo.png"; @@IMG_BANER = '<img align="middle" src="'.$logo.'" width="200">';
Get basic info of current logged in user
Trigger to get basic information of the current logged in user. e.g. name, lastname, address, phone and so on.
$userUid=@@USER_LOGGED; $userInfo = userInfo($userUid); @@userEmail = $userInfo ['mail']; @@userName = $userInfo ['firstname']." ".$userInfo ['lastname'];
Get department of current logged in user
It gets the department of a logged in user.
$userUid=@@USER_LOGGED; $userInfo = userInfo($userUid); $sql = "SELECT CON_VALUE FROM CONTENT WHERE CON_ID = '".$userInfo['department']."' AND CON_CATEGORY = 'DEPO_TITLE'"; $res = executeQuery($sql); @@department = $res[1]['CON_VALUE'];
Standard email template
Template commonly used to send dynamic notifications with a trigger.
@#IMG_BANER Dear @#user_name, @#body Kind regards, Company Name Team
Send simple email notification
It is commonly used since the notification might tend to change the message or the message might be sent based on certain conditions of the flow.
@@message="There is a new request # ".@@APP_NUMBER." that requires your attention. "; @@subject="New request # ".@@APP_NUMBER.""; $app = @@APPLICATION; $to = $nextUserEmail; $from = $emailFrom; $subject = @@subject; $aFields['user_name'] = $contact_person; $aFields['body']= @@message; PMFSendMessage($app, $from, $to, '', '', $subject, 'notifications.html', $aFields, '');
Send notification with generated document attached
Purpose of this trigger is to get the output document generated and send in an email notification.
$aAttachFiles = array(); $caseId = @@APPLICATION; $outDocDef = "245940083594e45d3c708d7062206599"; // Output Document UID: $outDocQuery = "SELECT AD.APP_DOC_UID, AD.DOC_VERSION, C.CON_VALUE AS FILENAME FROM APP_DOCUMENT AD, CONTENT C WHERE AD.APP_UID='$caseId' AND AD.DOC_UID='$outDocDef' AND AD.APP_DOC_STATUS='ACTIVE' AND AD.DOC_VERSION = ( SELECT MAX(DOC_VERSION) FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND DOC_UID='$outDocDef' AND APP_DOC_STATUS='ACTIVE') AND AD.APP_DOC_UID = C.CON_ID AND C.CON_CATEGORY = 'APP_DOC_FILENAME'"; $outDoc = executeQuery($outDocQuery); if (is_array($outDoc) and count(outDoc) > 0) { $path = PATH_DOCUMENT . $caseId . PATH_SEP . 'outdocs'. PATH_SEP . $outDoc[1]['APP_DOC_UID'] . '_' . $outDoc[1]['DOC_VERSION']; $filename = $outDoc[1]['FILENAME']; $app_string=@@APPLICATION; $a = substr($app_string, 0, 3); $b = substr($app_string, 3, 3); $c = substr($app_string, 6, 3); $d = substr($app_string, 9); $path = PATH_DOCUMENT."$a/$b/$c/$d/".'outdocs/'. $outDoc[1]['APP_DOC_UID'] . '_' . $outDoc[1]['DOC_VERSION']; $aAttachFiles[$filename . '.pdf'] = $path . '.pdf'; } $app = @@APPLICATION; $to = 'sample@sample.com'; $from = 'sample@sample.com'; $subject = 'New email sample'; $aFields['user_name'] = 'User'; $aFields['body']= 'This is a sample email.'; PMFSendMessage($app, $from, $to, '', '', $subject, 'notifications.html', $aFields, $aAttachFiles);
Get current date
It gets the current date and is stored in PM variable.
@@currentDate = date('m-d-Y');
Get the email server configuration
Gets the email server configuration to then use when sending an email notification.
$emailSettings=getEmailConfiguration(); @@emailServerSetting=$emailSettings['MESS_FROM_MAIL'];
Basic update and insert to a database table
SQL Query to update and insert a database table. It is commonly used a simple query to update/insert a table when it comes to track/log specific information of the process so then create custom reports.
$query = 'SELECT * FROM PMT_CASE_APPROVAL where APP_UID="'.@@APPLICATION.'" '; $response = executeQuery($query); if(count($response) != ''){ //Update $update = "UPDATE PMT_CASE_APPROVAL SET USR_UID='".@@USER_LOGGED."', USR_NAME='".@@USR_USERNAME."', APPROVAL='".@@approval."' WHERE APP_UID='".@@APPLICATION."' "; $res = executeQuery($update); }else{ //Insert $insert = "INSERT INTO PMT_CASE_APPROVAL( APP_UID, USR_UID, USR_NAME, APPROVAL )VALUES( '".@@APPLICATION."', '".@@USER_LOGGED."', '".@@USR_USERNAME."', '".@@approval."' )"; $res = executeQuery($insert); }
Get supervisor of a user
@@hrUser = @@USER_LOGGED; //Get the manager user $positionDepartment = @@positionDepartment; do { $sqlSmanager = "SELECT DEP_PARENT, DEP_MANAGER FROM DEPARTMENT WHERE DEP_UID = '".$positionDepartment."'"; $resSmanager = executeQuery($sqlSmanager); $depParent = $resSmanager[1]['DEP_PARENT']; $manager = $resSmanager[1]['DEP_MANAGER']; $positionDepartment = $depParent; }while($manager=='' and $depParent!=''); //if there are not a manager the "admin" user will be the manager by default if($manager==''){ $manager = '00000000000000000000000000000001'; } @@managerUser = $manager;
JavaScript Code
Custom Approve, Reject and More Info Button
// Change the size and color of the buttons document.getElementById('form[rejectBtn]').setAttribute("style","background:red;border:1px solid #eeeeee;width:150px;"); document.getElementById('form[approveBtn]').setAttribute("style","background:green;border:1px solid #eeeeee;width:150px;"); document.getElementById('form[moreinfoBtn]').setAttribute("style","background:#3397e1;border:1px solid #eeeeee;width:150px;"); // Add events on the buttons document.getElementById('form[rejectBtn]').onclick = function() { document.getElementById("form[approval]").value = '2'; document.forms[0].submit(); } document.getElementById('form[approveBtn]').onclick = function() { document.getElementById("form[approval]").value = '1'; document.forms[0].submit(); } document.getElementById('form[moreinfoBtn]').onclick = function() { document.getElementById("form[approval]").value = '3'; document.forms[0].submit(); }
Multi-tab form
The purpose of this multi-tab form is to merge long forms into tabs. The multi-tab form uses sub-forms. In order to add the sub-forms to a tab, it is used JavaScript functions. For passing from one tab to another, it is used a button which has a piece of JS code in its on-click event.
// Set active tab #0 $("#tabs" ).tabs({active: 0}); // Hide sub-forms $("[name='field-New Account Setup General Information']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); // Hide submit button $('#submit000000050').hide(); $('#panel0000000002').hide(); $('#tab1').click(function() { $("[name='field-New Account Setup General Information']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab2').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").show( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab3').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab4').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab5').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").show( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab6').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab7').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").show( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab8').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); }); $('#tab9').click(function() { $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").show( "blind", {}, 500 ); }); //Show NewAccountSetupAccountInformation document.getElementById('form[button0000000001]').onclick = function() { $("#tabs" ).tabs({active: 1}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").show( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } //Show New Account Setup EMSD Account Team document.getElementById('form[button0000000002]').onclick = function() { $("#tabs" ).tabs({active: 2}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } //Show New Account Setup Account Types and Services document.getElementById('form[button0000000003]').onclick = function() { $("#tabs" ).tabs({active: 3}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } //Show New Account Setup Accounting Information document.getElementById('form[button0000000004]').onclick = function() { $("#tabs" ).tabs({active: 4}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").show( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } //Show New Account Bill To Address document.getElementById('form[button0000000005]').onclick = function() { $("#tabs" ).tabs({active: 5}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } //Show New Account Setup Ship To Address document.getElementById('form[button0000000010]').onclick = function() { $("#tabs" ).tabs({active: 6}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").show( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } // Show New Account Setup On-Site Labor Locations document.getElementById('form[button0000000007]').onclick = function() { $("#tabs" ).tabs({active: 7}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").show( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").hide( "blind", {}, 500 ); $('#submit000000050').hide(); } // Show New Account Setup Account Team Comments document.getElementById('form[button0000000008]').onclick = function() { $("#tabs" ).tabs({active: 8}); $("[name='field-New Account Setup General Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup EMSD Account Team']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Types and Services']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Accounting Information']").hide( "blind", {}, 500 ); $("[name='field-New Account Bill To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Ship To Address']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup On-Site Labor Locations']").hide( "blind", {}, 500 ); $("[name='field-New Account Setup Account Team Comments']").show( "blind", {}, 500 ); $('#submit000000050').show(); }
Get total sum of a grid's column
The purpose of this JS code is to store the total sum of a grid's column into a PM variable.
jQuery("#form-uid").setOnchange(function(newvalue, oldvalue){ $("#field-id").setValue($('#sum-gridName-fieldName').val()); });
Hide and show fields based on certain condition
The purpose of this function is to hide/show a field based on a certain condition of a field.
$('#field-id').setOnchange(function(newV,prev){ showHide(newV); }); function showHide(newV){ if(){ $('#field-name').show(); } else{ $('#field-name').hide(); } }
- No labels