Questions and discussion about using ProcessMaker: user interface, running cases & functionality
By azatrath
#818790
hi all,

i got a weird acting trigger today. i wrote a trigger and a template for reminder mail focused on this topic viewtopic.php?t=709185.the trigger is
Code: Select all
$now = date("Y-m-d H:i:s");
function encode_items($arr) {
	foreach ($arr as $n => $v) {
		if (is_array($v)) {
			$arr[$n] = encode_items($v);
		} else {
			$arr[$n] = mb_convert_encoding($v,  'UTF-8', 'AUTO');
		}
	}
	return $arr;
}
header('Content-Type: text/html; charset=UTF-8');		

$query1 = "select USR_UID,APP_CURRENT_USER FROM APP_CACHE_VIEW 
where  APP_STATUS='TO_DO' AND DEL_THREAD_STATUS='OPEN' AND '$now' > DEL_TASK_DUE_DATE GROUP BY USR_UID";
$result1 = executeQuery($query1);
$result1 = encode_items($result1);
@=US = $result1;

for ($j = 1; $j <= count(@=US); $j++) {
	$US02 = @=US[$j]['USR_UID'];
	@=GS = NULL;
	$query2 = "select APP_CURRENT_USER GS01,CONCAT(APP_NUMBER,' ',APP_TITLE) AS GS02,APP_TAS_TITLE AS GS03,TIMESTAMPDIFF(HOUR, DEL_TASK_DUE_DATE, NOW()) AS GS04 FROM APP_CACHE_VIEW 
	where  APP_STATUS='TO_DO' AND DEL_THREAD_STATUS='OPEN' AND '$now' > DEL_TASK_DUE_DATE AND USR_UID='$US02' ORDER BY APP_CURRENT_USER";
	$result2 = executeQuery($query2);
	$result2 = encode_items($result2);
	@=GS = $result2;
	
	$aUser = userInfo($US02);
	$manager = userInfo($aUser['reportsto']);
		
	@@return = PMFSendMessage(@@APPLICATION, "PM Alert <info@kc.com>", $aUser['mail'], "", "", " OverDue Cases", "overDueCases.html", array(''), array(''), true, 0, "");
};
and the template is
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<p>Overdue Cases ::</p>
<table border="1" style="height: 5mm; width: 180mm;">
<tbody>
<tr>
<td><font size="1"><b>Cases</b></font></td>
<td><font size="1"><b>Tasks</b></font></td>
<td><font size="1"><b>Overtime</b></font></td>
</tr>
<!--@>GS-->
<tr>
<td><font size="1">@#GS02</font></td>
<td><font size="1">@#GS03</font></td>
<td style="width: 15mm; height: 5mm;"><font size="1">@#GS04 Saat</font></td>
</tr>
<!--@<GS--></tbody>
</table>
<p></p>
</body>
</html>
everything is working well when i execute case by myself, and it sends each employee's overduecases to them
i copy amos's overDueCases.php file to execute the trigger everyday.
Code: Select all
<?php
$serverAddress = "http://192.168.2.220"; //set to the server's address
$workspace = 'kozacarpet'; //set to the workspace which is 'workflow' by default
$user = 'bot';  //set to user who is assigned to a case in the process to run trigger
$password = '*******'; //set to password of the user
$caseId = '1107177735bf7e765674222073532032'; //set to case's ID
$triggerId = '6296691895bfba2063e64d7096382547'; //set to the trigger's ID

ini_set("soap.wsdl_cache_enabled", "0");
ini_set('error_reporting', E_ALL);
ini_set('display_errors', True);
      
$client = new SoapClient("$serverAddress/sys$workspace/en/neoclassic/services/wsdl2");
$md5Pass = 'md5:'. hash('sha256',$password); 
$params = array(array('userid'=>$user, 'password'=>$md5Pass));
$result = $client->__SoapCall('login', $params);
 
if ($result->status_code == 0)
   $sessionId = $result->message;
else
   print "Unable to connect to ProcessMaker.\nError Number: $result->status_code\n" .
         "Error Message: $result->message\n";
 
#look up the caseId and delIndex with the caseList() web service and the triggerIndex in MySQL
$params = array(array(
   'sessionId' => $sessionId, 
   'caseId' => $caseId,
   'triggerIndex' => $triggerId,
   'delIndex' => '1' //assuming first task in case
));
$result = $client->__SoapCall('executeTrigger', $params);
if ($result->status_code != 0)
   print "Error: $result->message \n";
else
   print_r($result);
?> 
when it execute trigger with task schedule, the trigger sends same template which is the first UID's overduecases to each employee.

i searched the problem more deeply and saw it, when i go manually second query works well.
when i go task schedular, it searched depands on first UID it get.
Code: Select all
$US02 = @=US[$j]['USR_UID'];
this line stay still i tried foreach fucntion too. manuel works change this line and task scheduler hold same this line.

is it possible to trigger act weird at cases or Task Scheduler?

btw i tried this topic too viewtopic.php?t=730533 same failure i get

When i run a case by myself
Ekran Alıntısı.PNG
Ekran Alıntısı.PNG (47.71 KiB) Viewed 3062 times
When i execute task Scheduler
Ekran Alıntısı-1.PNG
Ekran Alıntısı-1.PNG (51.43 KiB) Viewed 3062 times
User avatar
By amosbatto
#819306
I suspect that the problem is that each time the email template is used to generate the email, the case variables (stored in the APPLICATION.APP_DATA field in the database) have not changed, so the @=GS array is the same every time. What you need to do is pass the @=GS array as a variable to the PMFSendMessage() function like this:
Code: Select all
$aVars = array(
    'GS' => @=GS
);
@@return = PMFSendMessage(@@APPLICATION, "PM Alert <info@kc.com>", $aUser['mail'], "", "", " OverDue Cases", "overDueCases.html", $aVars);
The other way to handle this is to call PMFSendVariables() before calling PMFSendMessage(), but that is more complicated.
By azatrath
#821843
amosbatto wrote: Mon Nov 26, 2018 6:07 pm I suspect that the problem is that each time the email template is used to generate the email, the case variables (stored in the APPLICATION.APP_DATA field in the database) have not changed, so the @=GS array is the same every time. What you need to do is pass the @=GS array as a variable to the PMFSendMessage() function like this:
Code: Select all
$aVars = array(
    'GS' => @=GS
);
@@return = PMFSendMessage(@@APPLICATION, "PM Alert <info@kc.com>", $aUser['mail'], "", "", " OverDue Cases", "overDueCases.html", $aVars);
The other way to handle this is to call PMFSendVariables() before calling PMFSendMessage(), but that is more complicated.
it works ! ty amos,
may i learn other way too ?
User avatar
By amosbatto
#821857
It's like this:
Code: Select all
$aVars = array(
    'GS' => @=GS
);
PMFSendVariables(@@APPLICATION, $aVars);
@@return = PMFSendMessage(@@APPLICATION, "PM Alert <info@kc.com>", $aUser['mail'], "", "", " OverDue Cases", "overDueCases.html");

Web3 development encompasses creating decentralize[…]

The Upland Clone Script, offered by Dappsfirm, rep[…]

Dappsfirm offers a bet365 clone script that mirror[…]

🚀 Tauchen Sie mit Immediate Alora AI in die Welt d[…]