Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.

Moderator: amosbatto

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 skhaitan
#823847
Hi, I am trying to automate a script which is setup as follows (followed the forum post here)
process automation.JPG
process automation.JPG (75.19 KiB) Viewed 200 times
In the above process , sign test displays a form to sign and then check if the vendor has signed(API call) and statis , it moves to "Status Completed" task. Gateway conditions :

Check Status : @@docsignstatus != "completed"
Status Completed : @@docsignstatus == "completed"

"Check Status" task has following script :
Code: Select all
//set to the ID of the Self Service task in the "Return To Unassigned" process
//or use PMFGetUidFromText() to get the task ID:
$taskId = '4601691715ca78524b9f696056365990';

$anHourAgo = date('Y-m-d H:i:s', strtotime('-2 minutes'));

//Fetch cases that are unassigned
$sql = "SELECT * FROM APP_DELEGATION 
    WHERE TAS_UID='$taskId' AND DEL_THREAD_STATUS='OPEN' AND USR_UID = '0' ";  
$aDelegations = executeQuery($sql);

if (!isset(@=aRoutedCases)) {
	@=aRoutedCases = array();
}

$g = new G();
$g->sessionVarSave();
$_SESSION['USER_LOGGED'] = '4203070365c1914bf5d8230065328221';
foreach($aDelegations as $aDel) {
	$aVars = array(
		//'returnToUnassigned' => true,
		'docsignstatus'	=> 'completed'
	);
	
	PMFSendVariables($aDel['APP_UID'], $aVars);  
	PMFDerivateCase($aDel['APP_UID'], $aDel['DEL_INDEX'],true);
}
$g->sessionVarRestore();
I am fetching all tasks that is unassigned folder and sending variable "docsignstatus" as completed. When I am running thr trigger manually (by assigning to a user) , PMFDerivateCase returns 0.

If I am running
Code: Select all
> php -f  /var/www/processmaker/workflow/engine/bin/timereventcron.php
this returns "No existing records to continue a case, on date "2019-04-08 17:40:37 (UTC +00:00)"

timer is set to run every 5 minutes

Please assist where am I going wrong. This is very urgent.
User avatar
By amosbatto
#823850
Your process doesn't make any sense to me. I suspect that you copied some code from another example without understanding what the code is doing. (By the way, you didn't provide a link to the post that you used as an example.)

Can you describe what you are trying to achieve?

The code that you are using is checking if a user has claimed a self service task, which doesn't look to be what you want, so you shouldn't have AND USR_UID = '0' in your query.
User avatar
By amosbatto
#823851
Your process doesn't make any sense to me. I suspect that you copied some code from another example without understanding what the code is doing. (By the way, you didn't provide a link to the post that you used as an example.)

Can you describe what you are trying to achieve?

The code that you are using is checking if a user has claimed a self service task. Is your "Check Status" task a Self Service task? Is $taskId set to the ID of the "Check Status" task?

You shouldn't be arbitrarily changing the logged-in user, so delete this line:
$_SESSION['USER_LOGGED'] = '4203070365c1914bf5d8230065328221';

You need to specify the assigned user when routing the case:
PMFDerivateCase($aDel['APP_UID'], $aDel['DEL_INDEX'], false, $aDel['USR_UID']);
By skhaitan
#823861
Hi amosbatto,

Thankyou for replying.

I referred to "viewtopic.php?t=730175" as example. I copied the code and tried to modify it a bit to see if it can work for my example.

The example above was fetching all tasks that was initiated an hour ago. but i wanted to fetch unassigned tasks. So on checking the resultset, the unassigned tasks had USR_UID = 0 so I added that to the where clause. Please correct me what can I do to have the result expected?

My requirement is not to check if a user has claimed a self service task. I don't want user to claim the self service task as this needs to be done automatically.

My purpose :
Every 5-10 minutes , without user being logged in , a script should automatically check the "docsignstatus" variable for each case in "Check Status "task. if the "docsignstatus" has changed to "completed" (by making an api call in the trigger) , then that case should automatically be moved to the next task in process.

Can you please assist what would be the best way to achieve this.

Thanks in Advance
User avatar
By amosbatto
#824002
The trigger code you posted is different from your description.

Your trigger code sets the "docsignstatus" variable to "completed" and then routes on the case to the gateway. However your description is that the trigger checks if "docsignstatus" variable to "completed" before routing.

According to your code, "Check Status" is a Self Service task and you are only searching for cases where the "Check Status" task is not yet assigned to a user. Is that what you want?

Here is my best guess what you want for your trigger in the "Script to check Status" script task:
Code: Select all
$checkStatusTaskId = '4601691715ca78524b9f696056365990'; //set to ID of your "Check Status" task
$userIdToAssign = '1234567890abcdef1234567890abcdef'; //set to ID of user to automatically assign to task

//Fetch open cases currently in the "Check Status" task which :
$sql = "SELECT AD.APP_UID, AD.DEL_INDEX, AD.USR_UID, A.APP_DATA 
    FROM APP_DELEGATION AS AD, APPLICATION AS A 
    WHERE AD.TAS_UID='$checkStatusTaskId' AND AD.DEL_THREAD_STATUS='OPEN' AND AD.USR_UID = '0' 
    AND AD.APP_UID = A.APP_UID";  
$aDelegations = executeQuery($sql);

if (!isset(@=aRoutedCases)) {
	@=aRoutedCases = array();
}

$g = new G();
$g->sessionVarSave();

foreach ($aDelegations as $aDel) {
   $aCaseVars = unserialize($aDel['APP_DATA']);

   //if the docsignstatus variable is set to 'completed', then assign a user to the task and then route on
   //the case to the gateway
   if (isset($aCaseVars['docsignstatus']) and $aCaseVars['docsignstatus'] == 'completed') {
      $oCase = new Cases();
      $oCase->setCatchUser($aDel['APP_UID'], $aDel['DEL_INDEX'], $userIdToAssign);
      PMFDerivateCase($aDel['APP_UID'], $aDel['DEL_INDEX'], false, $userIdToAssign);
}

$g->sessionVarRestore();
Dell Printer Error State

You can fix the error by checking the network conn[…]

I have a problem where tasks on leaving the pause […]

Starting subprocess

I have a grid with multiple rows and it has a colu[…]

It is not a single field which is causing this is[…]