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.
#815172
Hi, I have a process (see attachments) that creates a task in another process (it's not a subprocess) to the current user.

In a script task after the task creation, I have this code:
Code: Select all
$appUID = @@APPLICATION;
$queryParent = "SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$appUID' ORDER BY DEL_INDEX_PARENT DESC";
@@queryParent = $queryParent;
$resultParent = executeQuery($queryParent);
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
It allows me to redirect the user to the newly created task in the other process. The problem is that my 'parent application' doesn't go to the next task (which is an end event) because I called die() at the end of my code. If I don't call die(), it goes to the next step but it doesn't seem to redirect.

Any way to make it works ?

Thanks
Attachments
redirect.PNG
redirect.PNG (22.11 KiB) Viewed 517 times
#815177
do it this way:
Code: Select all
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
        PMFDerivateCase(@@APPLICATION, @%INDEX);
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
That way it should route on the case before redirecting to the other case.
#815193
amosbatto wrote: Fri Jul 13, 2018 6:53 pm do it this way:
Code: Select all
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
        PMFDerivateCase(@@APPLICATION, @%INDEX);
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
That way it should route on the case before redirecting to the other case.
Just tried and it did not work. I already tried that before.

Any other way to do this?
Thanks
#815203
Delete the script task. Instead set the trigger to fire after routing in the "Change project in order status" task. Then your original trigger should work, because at that point the database record in the APP_DELEGATION table will already be written for the routing, so it won't hurt to redirect to the other case.
Code: Select all
$appUID = @@APPLICATION;
$queryParent = "SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$appUID' ORDER BY DEL_INDEX_PARENT DESC";
@@queryParent = $queryParent;
$resultParent = executeQuery($queryParent);
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
#815218
amosbatto wrote: Tue Jul 17, 2018 11:12 pm Delete the script task. Instead set the trigger to fire after routing in the "Change project in order status" task. Then your original trigger should work, because at that point the database record in the APP_DELEGATION table will already be written for the routing, so it won't hurt to redirect to the other case.
Code: Select all
$appUID = @@APPLICATION;
$queryParent = "SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT='$appUID' ORDER BY DEL_INDEX_PARENT DESC";
@@queryParent = $queryParent;
$resultParent = executeQuery($queryParent);
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
Thanks but the 'Change Project In Order Status' is not a task. It,s a subprocess. There's no 'Execute After Routing' for this element. I could create the process with the PMFNewCase() function in the task before 'Update Quotation Status' but it would mean that I would manually enter the PRO_UID and the TAS_UID in PMFNewCase() in every new version and I don't really like this idea.

It's easier to choose the process and task from the subprocess element (visually) so if there is a solution with that in mind, it would be perfect
#815224
I bet the reason why PMFDerivateCase() isn't working is because the @@INDEX is not correct. It is probably still set to the delegation index of the task prior to the subprocess. Also, the @@USER_LOGGED probably isn't correct. Try this:
Code: Select all
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
        $caseId = @@APPLICATION;
        $taskId = PMFGetTaskUID('Redirect to new task', @@PROCESS);
        $sql = "SELECT * FROM APP_DELEGATION WHERE APP_UID='$caseId' AND TAS_UID='$taskId' ORDER BY DEL_INDEX DESC";
        $aCurrentTask = executeQuery($sql);
        $g = new G();
        $g->sessionVarSave();
        PMFDerivateCase(@@APPLICATION, $aCurrentTask[1]['DEL_INDEX'], false);
        $g->sessionVarRestore();
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
Does that work?
#815239
amosbatto wrote: Thu Jul 19, 2018 12:45 am I bet the reason why PMFDerivateCase() isn't working is because the @@INDEX is not correct. It is probably still set to the delegation index of the task prior to the subprocess. Also, the @@USER_LOGGED probably isn't correct. Try this:
Code: Select all
if(!empty($resultParent) && count($resultParent) > 0)
{
	$newCaseUID = $resultParent[1]['APP_UID'];
        $caseId = @@APPLICATION;
        $taskId = PMFGetTaskUID('Redirect to new task', @@PROCESS);
        $sql = "SELECT * FROM APP_DELEGATION WHERE APP_UID='$caseId' AND TAS_UID='$taskId' ORDER BY DEL_INDEX DESC";
        $aCurrentTask = executeQuery($sql);
        $g = new G();
        $g->sessionVarSave();
        PMFDerivateCase(@@APPLICATION, $aCurrentTask[1]['DEL_INDEX'], false);
        $g->sessionVarRestore();
	G::header("Location: ../cases/cases_Open?APP_UID=$newCaseUID&DEL_INDEX=1");
	die();
}
Does that work?
It has the same behavior as before. It redirect but the main (parent) task is still opened unfortunately

【Q/微信729926040】如以删除请点网页快照,专业办理德国/法国/英国/加拿大各大学高端精仿文[…]

【Q/微信729926040】如以删除请点网页快照,专业办理德国/法国/英国/加拿大各大学高端精仿文[…]

【Q/微信729926040】如以删除请点网页快照,专业办理德国/法国/英国/加拿大各大学高端精仿文[…]

【Q/微信729926040】如以删除请点网页快照,专业办理德国/法国/英国/加拿大各大学高端精仿文[…]