Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
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.
User avatar
By Nikakhtar
#826148
Is there a way to reuse the database settings or load the database access method like executeQuery in my classes?

I've placed my class in the engine/classes/ folder, I'm loading it in the triggers with G::LoadClass(). In the trigger I would like to do something like:
Code: Select all
G::LoadClass('MyUtilsClass');
@@sometextfield = MyUtilsClass::getSupportDataFromCustomDatabaseField(<connection uid?>);
technically i need to know that what is the root directory to start from for INCLUDE '' statements in classes which is placed everywhere...
User avatar
By amosbatto
#826154
If you want to use the executeQuery() function, you need to load the workflow/engine/classes/class.pmFunctions.php file like this:
Code: Select all
G::LoadClass('pmFunctions');
$db = '1234567890abcdef1234567890abcdef'; //set to ID of database connection
$result = executeQuery("SELECT CLIENT_ID, CLIENT_NAME FROM CLIENTS");
$firstClient = $result[1]['CLIENT_NAME'];
If you add the file workflow/engine/classes/class.MyUtilsClass.php, then you can load it this way in your trigger:
Code: Select all
G::LoadClass('MyUtilsClass');
@@sometextfield = MyUtilsClass::getSupportDataFromCustomDatabaseField(<connection uid?>);

Note: The recommended way to do this is to create a plugin with the PMFunction class. The advantage of creating a plugin is that it doesn't get overwritten each time you upgrade ProcessMaker.
User avatar
By Nikakhtar
#826179
tnx but i did the same as what u told and it gives me "Something went wrong"...
all the functions in my class file are okay, and work in triggers...
i placed my class file in "workflow/engine/classes/class.methods.php"
Code: Select all
<?php 
G::LoadClass('pmFunctions');
class methods{
function Insert_into_form($Form_Id, $Requester_Id, $Requester_Department, $Submit_Date)
  {
    $db = '5151137655ccd90d78d7310084434072';
    $sql = "INSERT INTO `form`(`Id`, `Requester_Id`, `Requester_Department`, `Submit_Date`) VALUES ('$Form_Id', '$Requester_Id', '$Requster_Department', '$Submit_Date')";
    executeQuery($sql, $db);
  }
}
?>
then i added "G::LoadClass('methods');" in trigger.
and then added methods::Insert_into_form(@@Form_Id, @@USER_LOGGED, @@Requester_Department, @@Submit_Date); in the same trigger...
are u sure when i add G::LoadClass('pmFunctions'); in my class file, my class can find Gulliver G class??
User avatar
By amosbatto
#826187
It looks like they screwed up G::LoadClass() when they changed to Laravel in PM 3.2.2 and later.

This worked for me. I created the file workflow/engine/classes/class.myCode.php with this content:
Code: Select all
<?php

class MyCode {
	public function MyFunction() {
		$g = new G();
		$g->loadClass('pmFunctions');
		
		$aUsers = executeQuery("SELECT USR_UID, USR_USERNAME FROM USERS");
		return $aUsers;
	}
}
Then in my trigger in a process, I used this code:
Code: Select all
require_once "classes/class.myCode.php";

$mC = new MyCode();
@=users = $mC->myFunction();
PS: If you are executing this in a trigger, then you should avoid anything that throws a warning in recent versions of PHP, because PM is configured to throw errors for warnings in triggers.
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]