Trigger Examples
- 1 Trigger Examples
- 1.1 Starting a Case
- 1.1.1 ProCount Examples:
- 1.1.2 Enterprise Upstream Example:
- 1.1.3 Authentication
- 1.1.4 Creating the Case
- 1.1.5 Routing the Case
- 1.2 Adding Case Notes
- 1.2.1 Adding Permissions
- 1.2.2 Accessing Case Notes
- 1.2.3 Adding a Note via PHP
- 1.3 Exporting Documents to a Shared Drive
- 1.3.1 Host Environment Setup
- 1.3.2 Workflow code
- 1.4 Exporting files to FTP with TLS SSL Encryption
- 1.4.1 PHP Trigger code:
- 1.5 Getting an API URL
- 1.5.1 Example
- 1.6 Getting Case Variables
- 1.6.1 Example - PM Function
- 1.6.2 Example - Reporting Table
- 1.7 Using a REST Service call to get data for ProcessMaker Controls
- 1.7.1 Example - Get
- 1.7.2 Example - POST
- 1.1 Starting a Case
Starting a CaseProCount Examples:ProCount Trigger Important info.txt Enterprise Upstream Example: | To create a new case in ProcessMaker, you will need to call their REST API. The process consists of three steps:
The information you need to create the case includes:
You can either have these pre-configured in the system, or you may gather the required information through the resources provided in the ProcessMaker REST API. To view ProcessMakers full API Documentation, see ProcessMaker API documentation.. AuthenticationThe request needs to be authenticated against their security provider, with the following information:
A recommended approach for automated REST service calls is to have a service account created in the workspace for your product, and then use an impersonate feature to create new workflow cases as a specific user. URL: http://{server}/{workspace}/oauth2/token
For more information, see Process Maker access Token documentation. Creating the CaseOnce you have signed in, you can make a POST call to create a case. The input parameters are:
To impersonate as a specific user, you add impersonate to the URL path and include a user UID for the user you would like to impersonate. URL: http://{server}/api/1.0/{workspace}/cases/impersonate Example Body:
All Three Values can be obtained via running a case in DEBUG mode, these values will display the ProcessID, TaskID, and USR_UID (Note* use the P2Application User for proper configuration) For more information, see the ProcessMaker New Case documentation. Routing the CaseThe third API call is required to route the case to the first task in the workflow. You must:
URL: http://{server}/api/1.0/{workspace}/cases/{app_uid}/route-case To help standardize and limit the amount of work needed for a configuration, we have included a group "Automated Services," and it is highly recommended to attach this user group to the target starting task of a process using this trigger. This is due to when the process is exported and imported, we are able to keep that automated services connection, and all users have to do upon an install is assign a user to the group to associate it to all the proper tasks. For more information, see the Process Maker Case Routing documentation. | ||||||||||
Adding Case Notes | Adding case notes can be a useful tool to track what is happening as a process progresses. It has the benefits of being able to be read by anyone who has permissions to read the case notes as well as sending an email when the notes are added. Adding PermissionsTo be able to access case notes, users have to be granted permissions within the Workflow Designer.
9. To save your changes, click Save. Accessing Case NotesAlthough there are two ways to access case notes, they both involve clicking on the speech bubble icon
Adding a Note via PHPThere may be a time when you want to add a case note from within a trigger, for example if you want to save the user from manually add notes. If so, you can add notes using the following code sample. Example PHP: $oCaseNotes = new AppNotes(); | ||||||||||
Exporting Documents to a Shared Drive | In some cases, you may need to upload documents from a workflow process to a shared drive on a local windows network. This requires 2 steps:
Host Environment SetupThis step should have already been completed by release management. You can find the configuration steps in the Environment Configuration documentation. Workflow codeThe following PHP code is an example of how we can use a trigger within a workflow to copy all documents associated with a case to the shared drive: // Get Case ID - then search for all files attached to case $caseId = @@APPLICATION; $query = "SELECT APP_DOC_UID, DOC_VERSION, APP_DOC_TYPE FROM APP_DOCUMENT WHERE APP_UID = '".$caseId."' AND APP_DOC_STATUS = 'ACTIVE' ORDER BY APP_DOC_INDEX"; $aFiles = executeQuery($query); $path = (new G)->getPathFromUID($caseId); // If files exist, loop through and add them to shared drive if (is_array($aFiles) and count($aFiles) > 0) { foreach($aFiles as $aFile) { $d = new AppDocument(); $aDoc = $d->Load($aFile['APP_DOC_UID'], $aFile['DOC_VERSION']); $filename = $aDoc['APP_DOC_FILENAME']; $ext = pathinfo($filename, PATHINFO_EXTENSION); //Check to see if document is OUTPUT - if so, we need to update some variables - remove this code is all you want is input documents if ($aFile['APP_DOC_TYPE'] == "OUTPUT"){ $ext = "pdf"; // Set to doc if you want a word '.doc' format $path .= PATH_SEP. 'outdocs'; $filename .= ".".$ext; } $filePath = PATH_DOCUMENT . $path . PATH_SEP. $aFile['APP_DOC_UID'] . '_' . $aFile['DOC_VERSION'] . '.' . $ext; //This is the Root of the shared drive on the host system, i.e. where PM is installed - This should only change when the Root changes $rootDirectory = "/mnt/workflow/"; // Add any sub-directories you want here - can have multiple levels. MUST END WITH "/" $subDirectory = "testDirectory/"; // Check to see if Directory exists - if not, create it if (!file_exists($rootDirectory.$subDirectory)) { mkdir($rootDirectory.$subDirectory, 0700); } //Copy file to shared drive copy($filePath, $rootDirectory.$subDirectory.$filename); } } | ||||||||||
Exporting files to FTP with TLS SSL Encryption | It is possible to export files from a workflow to an FTP with TLS/SSL Encryption with the code below. Note: An FTP server with encryption is different from an SFTP server. If you are adding an input document through a file/fileupload control on a document control within a ProcessMaker Task, the trigger WILL NOT work if:
It will work in later sections, in a different dynaform step or the Assignment or Routing steps of the task. PHP Trigger code: $conn = ftp_ssl_connect($host, $portNumber ); | ||||||||||
Getting an API URL | This section contains an example of the trigger IFS Workflow uses to get the @@apiUrl and @@apiUrlToken from the PMT_EXTERNAL_API table. We use this table for both security and externalizing where we store the URLs for each product. This is done because if the URL needs to change, then the change only needs to be made in one place, as opposed to changing the URL for each trigger that needs access to the URL in question. Before using REST endpoints, make sure the information is configured in the PMT_EXTERNAL_API table. For more information about configuring the endpoints, read the Environment Configuration documentation. In some cases, you might need to connect to more than one system. If this is the case, the recommend steps are:
Example
| ||||||||||
Getting Case Variables | In some cases, you may want to get variables and data from another case, or even a different workflow completely. There are two methods to achieve this:
Both of these scenarios achieve the same results. Which method you should use should really depend on each unique situation.
Be aware of these issue when using either method, and be sure to test thoroughly. Where possible, add documentation that will help others know what has been done and why. Example - PM FunctionThis example includes the following steps:
Task Setup:
Example - Reporting TableThis example uses a query a reporting table that is created in the New Well Approval workflow . For instructions on how to create a reporting table, see the Process Maker Wiki . Task Setup:
| ||||||||||
Using a REST Service call to get data for ProcessMaker Controls | Wherever possible, IFS Workflow uses REST service calls to retrieve data for use in the various PM Controls, and to save data back within the product's database. Below are two simple examples of using PHP cURL to connect to a REST api to GET data to populate a Dropdown Control, and POST the data back to the server. Note: @@apiUrl and @@apiToken are fields that are populated from the EXTERNAL_API table using the Get Api URL trigger. Example - GetThe highlighted section is where the actual call to the rest service occurs to get access to the data that the server has made available. The in-highlighted section is where the data manipulation occurs to get the data in the desired format and into the ProcessMaker variables being used.
Example - POSTIn this example, the extra options are highlighted. This includes options that are set when the REST API is expecting a JSON array. It could also be possible to simply have the data sent as part of the URL, in which case the JSON array of data would not be needed.
|
For help troubleshooting errors encountered when working with Triggers, see Trigger Error Handling.
Copyright© 2024 IFS AB. Copying prohibited. All rights reserved.