Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#825480
Hi everyone,

I have a process where user A fill in data for user B.
User A then choose user B name and close the case.
I tried to use the trigger below but the case still under user A
Code: Select all
$taskId = @@TASK;
$userlog = @@USER_LOGGED;
if ($taskId == 'xxxx'){
	if ($userlog != @@userB){
		@@USER_LOGGED = @@userB;	
	}
}
Is there a way to make this happen?

Your help is appreciated.
#825495
It is recommended to use a Process Supervisor to change the data of a case which is assigned to another user.

If you want to change the ownership of the case, then you should use Cases::reassignCase().

If you want to change the data of another case, then you should use PMFSendVariables().

If you want to route on another case which isn't the current case, then you can use PMFDerivateCase() but reset the system variables afterwards back to the current case, like this:
Code: Select all
$g = new G();
$g->sessionVarSave();
PMFDerivateCase($caseId, $delIndex, true, $assignedUserId);    
$g->sessionVarRestore();
Where $assignedUserId is the ID of the user assigned to the current open task in the case.
See: viewtopic.php?f=47&t=713218&p=794510#p794510
#825579
amosbatto wrote: Fri Jul 19, 2019 7:51 pm It is recommended to use a Process Supervisor to change the data of a case which is assigned to another user.

If you want to change the ownership of the case, then you should use Cases::reassignCase().

If you want to change the data of another case, then you should use PMFSendVariables().

If you want to route on another case which isn't the current case, then you can use PMFDerivateCase() but reset the system variables afterwards back to the current case, like this:
Code: Select all
$g = new G();
$g->sessionVarSave();
PMFDerivateCase($caseId, $delIndex, true, $assignedUserId);    
$g->sessionVarRestore();
Where $assignedUserId is the ID of the user assigned to the current open task in the case.
See: viewtopic.php?f=47&t=713218&p=794510#p794510
Dear Amos,

I have tried on OPEN case and it works well, but it did not work on CLOSED case.
Is there a way to make this happen?

Below the trigger code I've tried.
Code: Select all
$query = "SELECT ad.APP_NUMBER as caseno, ad.DEL_INDEX as delindex, ad.USR_UID as oriuser, sm.NEWPIC as newuser 
   FROM APP_DELEGATION as ad, PMT_XXX as sm
   WHERE ad.TAS_UID = 'xxxxxxxxx' AND ad.APP_NUMBER = sm.APP_NUMBER and del_last_index = '1'  and 
   ad.USR_UID != sm.NEWPIC";
$cases = executeQuery($query);

foreach($cases as $case)
{
	$c = new Cases();
	$c->reassignCase($case["caseno"], $case["delindex"], $case["oriuser"], $case["newuser"]);
}

#825612
In your query, change:
del_last_index
To:
ad.DEL_LAST_INDEX

There is no way to reassign a task in a case to another user, when that task is already closed in the case. You should change the user assigned to the task before routing to the next task/end event. What exactly are you trying to do and why do you need it? Maybe there is a better way to do it.

PS: You could write directly to the database and change the APP_CACHE_VIEW.USR_UID and APP_DELEGATION.USR_UID fields from the ID of the old assigned user to the new assigned user, but I recommend against that, because you also have to search in the APP_HISTORY, APP_DOCUMENT, APP_MESSAGE and similar tables and make similar changes and it would remove the case from the history of the old assigned user.
#825622
Dear Amos,

Here's what i meant to do:

User A fill in details for User B
User A choose user B from group of users
User A close the case but the ownership of the said case changes to User B
User B name will be displayed as the case owner when searching for the said case

The trigger runs well using code below:
Code: Select all
$casenumber = @@APP_NUMBER;
$currentUser = @@USER_LOGGED;
$taskUID = @@TASK;
$newpic = @@NEWPIC;

$query = "SELECT * FROM APP_DELEGATION 
WHERE USR_UID = '$currentUser' 
AND DEL_THREAD_STATUS = 'OPEN'
AND APP_NUMBER = '$casenumber'
AND TAS_UID = '$taskUID'";
$case = executeQuery($query);

$c = new Cases();
$c->reassignCase($case[1]['APP_UID'], $case[1]['DEL_INDEX'], $case[1]['USR_UID'], $newpic);
The problem now that there's some case that already closed but did not change the case owner.
So now I'm trying to change the CLOSED case to the User B.

If there's no other way, could you recommend which table i need to take a look to change it manually?

Thanks in advance.
#825631
There is no way to do it except to execute these commands directly to the database.
Off the top of my head, here are the SQL commands. You should test it with one case and verify that it works, before doing it with the other ones.
Code: Select all
mysql -u root -p
mysql> use wf_workflow;
mysql> UPDATE  APP_DOCUMENT AD 
   LEFT JOIN APP_CACHE_VIEW ACV  
   ON  ACV.APP_UID = AD.APP_UID AND ACV.DEL_INDEX=AD.DEL_INDEX
   SET  AD.USR_UID='XXXXXXXXXXXXXXXXXXXXXX' 
    WHERE ACV.APP_NUMBER=W AND ACV.TAS_UID='YYYYYYYYYYYYYYYYYYYY' AND
    ACV.USR_UID='ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
mysql> UPDATE  APP_MESSAGE AM 
   LEFT JOIN APP_CACHE_VIEW ACV  
   ON  ACV.APP_UID = AM.APP_UID AND ACV.DEL_INDEX=AM.DEL_INDEX
   SET  AM.USR_UID='XXXXXXXXXXXXXXXXXXXXXX' 
    WHERE ACV.APP_NUMBER=W AND ACV.TAS_UID='YYYYYYYYYYYYYYYYYYYY' AND
    ACV.USR_UID='ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
mysql> UPDATE  APP_DELEGATION AD 
   LEFT JOIN APP_CACHE_VIEW ACV  
   ON  ACV.APP_UID = AD.APP_UID AND ACV.DEL_INDEX=AD.DEL_INDEX
   SET  AD.USR_UID='XXXXXXXXXXXXXXXXXXXXXX' 
    WHERE ACV.APP_NUMBER=W AND ACV.TAS_UID='YYYYYYYYYYYYYYYYYYYY' AND
    ACV.USR_UID='ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
mysql> UPDATE APP_CACHE_VIEW SET USR_UID='XXXXXXXXXXXXXXXXXXXXXX' WHERE APP_NUMBER=W AND
    TAS_UID='YYYYYYYYYYYYYYYYYYYY' AND USR_UID='ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
mysql> exit;
(where XXXXXXXXXXXXXXXXXX is the ID of the new assigned user, W is the case number, YYYYYYYYYYYYYYYYY is the task ID, and ZZZZZZZZZZZZZZZZ is the old assigned user)
#825697
Dear Amos,

I've tried manually update the following tables APP_DELEGATION, APP_MESSAGE, APP_CACHE_VIEW and APP_DOCUMENT into the new user ie= 'mustaqim'. The case however still under previous user; refer picture below.

Is there any other table I need to change as well?
Attachments
user.PNG
user.PNG (38.76 KiB) Viewed 6957 times
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[…]