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.
By iliusha
#790303
Hi All,
How can i schedule one trigger to run at each hour in one application without creating a new case for that?
Thank You.
By zainab
#790304
Hello iliusha,

You can achieve this by calling your trigger from a script, which can be scheduled to run periodically on your server. Create the following script on your ProcessMaker server:
Code: Select all
<?php
$serverAddress = "http://example.com"; //set to the server's address
$workspace = 'workflow'; //set to the workspace which is 'workflow' by default
$user = 'admin';  //set to user who is assigned to a case in the process to run trigger
$password = 'p4sSw0rD'; //set to password of the user
$caseId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //set to case's ID
$triggerId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //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");
$params = array(array('userid'=>$user, 'password'=>$password));
$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);
?> 
Now follow these steps:
1. Edit your process to enable the Debug Mode.
2. Start a case in your process, but do not complete it.
3. Note down the Case ID from the debug mode.
4. Open your process and note down the Trigger UID of the trigger.
5. Replace these values in your script task.
6. Save the script and test it by executing the following command:
Code: Select all
php -f /opt/processmaker-3/shared/script.php 
7. If it works perfectly, edit your crontab file /etc/crontab, add the following line:
Code: Select all
0 1 * * * root php -f /opt/processmaker-3/shared/script.php 
In my case, script.php is located in /opt/processmaker-3/shared directory

Hope this helps.

Best Regards,
Zainab Sabunwala
By iliusha
#790308
Hi Zainab,

Thank you for your Solution, looks good - but, i'm receiving the folowing error:
# php -f trigger.php
Error: This case is assigned to another user

Also as i understand it will work only for specific cases, is it?
May you make it to work for All opened cases?
Thank you.
User avatar
By amosbatto
#790322
Iliusha,
Only a user who is assigned to an initial task in a process may start a case in that process. What I recommend is creating a new user whose password will never change which you only use for running this script. Then, assign that user to the initial tasks in all the processes where you want the script to start cases.

Another way to do this is to look up in the database who is assigned to each initial task and then login as that user using his/her password hash, but that is more complicated, because you have to use mysql_query() to do database queries.
By iliusha
#790326
Thanks,

Ok, it's a good idea. I can make one special user just for such cases - but anyway it's not working.
In case if i'm running this script using initial user - i'm receiving the following error:

/opt/workflow/engine/bin# php -f trigger.php
Error: This case delegation is already closed or does not exist - even if the case is Opened.

When i checked in Database - i found that actually there are 2 APP_UID (one of them - Open, the second - Closed) for the same case with 2 different users assigned.

select * from APP_DELEGATION where APP_UID='91024389058ef8dcae32fa9063680620';


"91024389058ef8dcae32fa9063680620" "1" "0" "0" "32571136258de5de5780ca1040183219" "18284896958dfc9e1868e82027691737" "92274150658ef568a34ca76004161209" "NORMAL" "1" "CLOSED" "3" "2017-04-13 17:40:10" "2017-04-13 17:40:10" "2017-04-13 17:40:26" "2017-04-14 17:40:10" "2017-04-14 15:04:10" "0" "0" "0" "0" "0" "0" "" "0"

"91024389058ef8dcae32fa9063680620" "2" "1" "1" "32571136258de5de5780ca1040183219" "76215881558eb77c70b5320065412863" "47042636458ef571c1f7191034042188" "NORMAL" "1" "OPEN" "3" "2017-04-13 17:40:26" "2017-04-13 17:47:25" "2017-04-13 17:48:33" "2017-04-13 17:44:26" "2017-04-13 17:43:38" "0" "0" "0" "0" "0" "0" "" "0"
By iliusha
#790328
Hi All,

I found - Case ID - was not set correct. Script is working ok now - but only for specific case. How can i use it for all opened cases?
Thank You.
By zainab
#790329
Hello iliusha,

The APP_DELEGATION stores record every time a task is derivated to next task. So for a single case there can be multiple entries depending on the number of tasks and derivations. Your APP_DELEGATION is CLOSED for one entry and OPEN for other, this indicates that one task has been completed and that the other task is OPEN for being worked on.

Your results show that you have completed the first task and have moved onto the second task, hence CLOSED for the first one and OPEN for the second one. The trigger that you are trying to execute is assigned to wich task, is it in your first task or the second one?

What you can do is start your process again initiating a new case, and do not complete the first task, and then run your script, this is for the case if your trigger is located in first task. If your trigger is located in second task, then in your script change the delIndex to "2":
Code: Select all
$params = array(array(
   'sessionId' => $sessionId,
   'caseId' => $caseId,
   'triggerIndex' => $triggerId,
   'delIndex' => '2' //Delegation Index for second task
));
The error appeared because delIndex was set to "1" and your case was in second task.

Hope this helps.

Best Regards,
Zainab Sabunwala
By iliusha
#790331
Hello Zainab,

Thank You, yes, you are right - the trigger is assigned to the second task - and i changed delIndex = to '2' - and everything works perfectly.
But how can i use this script for all cases - not only for specific ones?
Thank You.
By zainab
#790334
Hello iliusha,

If you want to use for all cases, you can directly start cases from the interface and execute the triggers. You can also use timer events if you want to set them periodically, please refer to the documentation below:
http://wiki.processmaker.com/3.0/Events ... tart_Event

As you had mentioned initially, you wanted to setup execution of trigger without starting a new case, that can be done through the above script.

Please let me know if this helps you.

Best Regards,
Zainab Sabunwala
By iliusha
#790335
Hello Zainab,

Yes, that's idea - i need to run one trigger without starting new case or do not be dependent by some cases. Actually, the task is to reassign the case to another user in case if the currently assigned user exceeded time for execution (due date).
Trigger - i have from this post: viewtopic.php?f=44&t=710344. (Thank's to Mishika)
What i need is to execute through cron this trigger for all cases (already opened).
Using Timer Events - will create new cases - which is not ok for me.

Thank You
By zainab
#790337
Hello iliusha,

Then the script I suggested above will work for you the best. Since it will execute periodically by configuring it in the crontab. This trigger will run independent of any cases.

One more option is you can create a separate process with this trigger, and code the trigger to check for pending cases of another process, which you want to reassign. And this can be configured to executed through script.

Hope this helps you.

Best Regards,
Zainab
By iliusha
#790339
Hello Zinab,

No, it is not working for any cases, i tried already - i should set exactly case id ($caseId - variable) - without this variable - script are not working.
Thank You.
By azatrath
#819132
zainab wrote: Thu Apr 13, 2017 8:17 am Hello iliusha,

You can achieve this by calling your trigger from a script, which can be scheduled to run periodically on your server. Create the following script on your ProcessMaker server:
Code: Select all
<?php
$serverAddress = "http://example.com"; //set to the server's address
$workspace = 'workflow'; //set to the workspace which is 'workflow' by default
$user = 'admin';  //set to user who is assigned to a case in the process to run trigger
$password = 'p4sSw0rD'; //set to password of the user
$caseId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //set to case's ID
$triggerId = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //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");
$params = array(array('userid'=>$user, 'password'=>$password));
$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);
?> 
Now follow these steps:
1. Edit your process to enable the Debug Mode.
2. Start a case in your process, but do not complete it.
3. Note down the Case ID from the debug mode.
4. Open your process and note down the Trigger UID of the trigger.
5. Replace these values in your script task.
6. Save the script and test it by executing the following command:
Code: Select all
php -f /opt/processmaker-3/shared/script.php 
7. If it works perfectly, edit your crontab file /etc/crontab, add the following line:
Code: Select all
0 1 * * * root php -f /opt/processmaker-3/shared/script.php 
In my case, script.php is located in /opt/processmaker-3/shared directory

Hope this helps.

Best Regards,
Zainab Sabunwala
hey zainab,

i have little problem about this one, i saw this topic after i opened new one here it is can you check it ?viewtopic.php?f=41&t=733124 i want to ask you, trigger act different on case or task schedular ?
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[…]