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

Moderators: ArturoRobles, ArturoRobles

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 incitegraphics
#793374
Hello, I've been reading through the wiki (I am a beginner) and have run into an issue that I can't seem to figure out.

I have a process that needs to route to a group based on the value of a field. I was able to locate the group ID for each of the groups, now I need to route the process.

For example, let's say that I have a select field called risk level with values low, med or high. If someone selects risk value low, route to group one, else if risk value is med, route to group two etc.

I have a variable to capture the value of risk level (i.e. @@risklevel == 'low'). I am trying to figure out how to route the process to the next step. I'm assuming I create a trigger, add the following example PHP code, select value based assignment and add both of the groups

if (@@risklevel == 'low') {
notify group one
}

else if (@@risklevel == 'med') {
notify group two
}

Sorry for the long message. If someone has an example I could see that would be much appreciated.
User avatar
By amosbatto
#793392
There are several ways to do this. One way is to create a process like this:
gatewayToRoute.png
gatewayToRoute.png (13.5 KiB) Viewed 1055 times
In "Task 1" have a dropdown box associated with the risklevel variable which has options with the keys "low" and "med"
Then, use these conditions in the properties of your gateway:
routingRulesForGateway.png
routingRulesForGateway.png (27.97 KiB) Viewed 1055 times
If you want you can also add a trigger like this in Task1 (but it isn't necessary):
Code: Select all
G::LoadClass("groups");
$g = new Groups();
$to = "";

if (!isset(@@risklevel) or @@risklevel == 'low') {
   $groupID = PMFGetUidFromText('Task for group 1', 'GRP_TITLE', @@PROCESS, @@SYS_LANG)[0];
}
elseif (@@risklevel == 'med') {
   $groupID = PMFGetUidFromText('Task for group 2', 'GRP_TITLE', @@PROCESS, @@SYS_LANG)[0];
}
  
$aUsers = $g->getUsersOfGroup($groupID);
for ($i = 0; $i < count($aUsers); $i++) {
   $to .= (empty($to) ? '' : ', ') . $aUsers[$i]['USR_EMAIL'];
}
PMFSendMessage(@@APPLICATION, '[email protected]', $to, '', '', 
   'Assigned to case #'[email protected]@APP_NUMBER, 'caseAssignment.html');

//remove this code if you don't want to route immediately to the next task:
PMFDerivateCase(@@APPLICATION, @%INDEX);
G::header("Location: casesListExtJsRedirector");
die();
(Don't just copy this code. Lookup each of these functions in the wiki so you understand what the code does.)

Another way is do this is to use a process like this:
valueBasedAssignmentProcess.png
valueBasedAssignmentProcess.png (6.64 KiB) Viewed 1055 times
where the second task uses Self Service Value Based Assignment and the variable @@assignedUsers.

Then use a trigger like this in the first task:
Code: Select all
G::LoadClass("groups");
$g = new Groups();
$to = "";

if (!isset(@@risklevel) or @@risklevel == 'low') {
   $groupID = PMFGetUidFromText('Task for group 1', 'GRP_TITLE', @@PROCESS, @@SYS_LANG)[0];
}
elseif (@@risklevel == 'med') {
   $groupID = PMFGetUidFromText('Task for group 2', 'GRP_TITLE', @@PROCESS, @@SYS_LANG)[0];
}
  
$aUsers = $g->getUsersOfGroup($groupID);
for ($i = 0; $i < count($aUsers); $i++) {
   $to .= (empty($to) ? '' : ', ') . $aUsers[$i]['USR_EMAIL'];
}
PMFSendMessage(@@APPLICATION, '[email protected]', $to, '', '', 
   'Assigned to case #'[email protected]@APP_NUMBER, 'caseAssignment.html');

@=assignedUsers = array($groupID);

//remove this code if you don't want to route immediately to the next task:
PMFDerivateCase(@@APPLICATION, @%INDEX);
G::header("Location: casesListExtJsRedirector");
die();
If you want to use Value Based Assignment instead of Self Service Value Based Assignment, then you need to use rand() to select a user from the group. See this example:
http://wiki.processmaker.com/3.0/Trigge ... ed_to_task

The 500 Internal Server Error is the general catch[…]

Really very nice blog information for this one and[…]

This is a long, lengthy and cumbersome process. T[…]

Great read for when on the road. The book provides[…]