Page 1 of 1

How to end a task with coding?

Posted: Mon Jul 29, 2019 7:18 am
by maabik
Hi,
I have to implement the workflow in the attached file:
In “Task 1”, when the user sends a form to be validated, two tasks will be created in parallel: “Task 2” and “Task 3”.
In “Task 3”, when the validator validates the form, “Task 4” will be created.
However, if the validator rejects the form, that will be sent to “Task 1” and “Task 2” must be ended.
My question to you is how to end a task after a validation check?can we do it using a code? Is there any trigger (code) example?
Thank you for your help.
Kind Regards.

Re: How to end a task with coding?

Posted: Tue Jul 30, 2019 6:02 am
by maabik
Hi,

Can you assist me on this?

Best Regards

Re: How to end a task with coding?

Posted: Thu Aug 01, 2019 1:22 am
by amosbatto
I created a programming example for you:
https://www.pmusers.com/index.php/Routi ... _loop_back

Re: How to end a task with coding?

Posted: Fri Sep 13, 2019 7:21 pm
by maabik
Hi,

First, i would thank you ror your feedbak.

Actually, your code makes an end to the parallel task as expected but i have an issue. i am executing two other triggers after routing wish both are executed twice (saving and sending mail twice). those two triggers are working fine if emove the trigger that ends the parallel task. my code is the following:
Code: Select all
//set to title of other parallel task:
	$otherParallelTask = 'Task1';
	$caseTile = @@caseTitle;
	$opTaskId = PMFGetTaskUID($otherParallelTask);
	
	if (empty($opTaskId)) {
		throw new Exception("Task '$otherParallelTask' not found!");
	}
	
	//look up other parallel task's delegation index in the database:
	$caseId = @@APPLICATION;
	$sql = "SELECT * FROM APP_CACHE_VIEW WHERE APP_UID='$caseId' AND 
		TAS_UID='$opTaskId' AND DEL_THREAD_STATUS='OPEN' ORDER BY DEL_INDEX DESC";
	$aTasks = executeQuery($sql);
	
	//if another open parallel task is found, then route it on:
	if (!empty($aTasks)) {
		$g = new G();
        $g->sessionVarSave();
		@@ret = PMFDerivateCase($caseId, $aTasks[1]['DEL_INDEX'], false, $aTasks[1]['USR_UID']);
        $g->sessionVarRestore();
       
	}
can you please help me on this?

Re: How to end a task with coding?

Posted: Tue Sep 17, 2019 12:08 am
by amosbatto
What version of ProcessMaker are you using? There is a bug is some versions of PM that prevents more than one trigger from executing during routing. Try combining your triggers into one trigger. For example, if you have 2 triggers after routing, then put the code from the two triggers into one trigger.

Re: How to end a task with coding?

Posted: Tue Sep 17, 2019 4:40 pm
by maabik
Hi,

I am using the cloud verion of PM"3.3.0 - Enterprise Edition".
Even i combined all triggers in one, the execution is done twice (i got the results doubled).
I tried to use the function "PMFDeleteCase()" to delete the desired case but i does not work since its returned value is 0.

any suggestions please?

Re: How to end a task with coding?

Posted: Tue Sep 17, 2019 6:00 pm
by amosbatto
PMFDeleteCase() only works when deleting a case which is still in the first task of its process. If in a later task, you need to use PMFCancelCase().

This line of code:
@@ret = PMFDerivateCase($caseId, $aTasks[1]['DEL_INDEX'], false, $aTasks[1]['USR_UID']);

sets the third parameter to false, so it routes on the other parallel task without executing any of its triggers in routing.

It is impossible for me to tell you why your triggers are executing twice without seeing your process. Post the .pmx file for your process and tell me exactly which triggers are executing twice and in which task.