Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
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 Throwaway
#813072
What would be the best way to go about having the same start one task/subprocess depending on if one of three users are logged (or a group) and if none of them are logged, then start a different task?

Start case -> If any of the 3 are logged -> task 1

-> If none of them are logged -> task 2
#813082
It is easy to check whether the user who starts a case is one of three users by looking at the @@USER_LOGGED system variable in a trigger:
Code: Select all
function checkIfLogged() {
   $aLoggedUsers = array(); //array of logged-in users from group, which is returned
   $aMembers = PMFGetGroupUsers( PMFGetGroupUID("Users Logged for Task1") );
   if (empty($aMembers)) {
      return array();
   }
   
   $aMemberIDs = array()
   foreach ($aMembers as $aMember) {
      $aMemberIDs = $aMember['USR_UID'];
   }

   if (in_array(@@USER_LOGGED, $aMemberIDs)) {
      return = array(@@USER_LOGGED);
   }
}       

//skip first task in process if at least one member of the "Users Logged for Task1" group isn't logged in:
if (count(checkIfLogged() == 0) {
   @@nextAssignedUser == @@USER_LOGGED;
   PMFDerivateCase(@@APPLICATION, @%INDEX, @@USER_LOGGED);
}     

Set this trigger to fire before the first step in the first task of the process.

However, it is much harder to check if any of three users are logged into PM (but don't have to be the person starting the case).

Login sessions in PM are managed by PHP and they expire when the $_SESSION superglobal variable becomes empty. For security reasons, PHP doesn't allow you know which other users are logged in.

You can query the LOGIN_LOG.LOG_INIT_DATE in the database, which will tell you when users logged-in, but there is no reliable way to know whether their login sessions have expired or not. When the user clicks on the "Logout" link in PM, that datetime will be registered in the LOG_END_DATE field, but nothing is written to the database when a login session expires after 24 minutes of inactivity (that time can be configured under Admin > System, "Cookie lifetime").


Here is the best that you can do:
Create a group named "Users Logged for Task1" and add users to it.
Then, use this trigger code:
Code: Select all
function checkIfLogged() {
   $aLoggedUsers = array(); //array of logged-in users from group, which is returned
   $aMembers = PMFGetGroupUsers( PMFGetGroupUID("Users Logged for Task1") );
   if (empty($aMembers)) {
      return array();
   }
   
   $aMemberIDs = array()
   foreach ($aMembers as $aMember) {
      $aMemberIDs = $aMember['USR_UID'];
   }

   if (in_array(@@USER_LOGGED, $aMemberIDs)) {
      $aLoggedUsers[] = @@USER_LOGGED;
   }

   //check if any of the members of the group have a login in the last 24 minutes: 
   $sMemberIDs = "'" . implode("','" $aMemberIDs) . "'";
   $time24mAgo = date('Y-m-d H:i:s', strtotime('-24 minutes'));
   $sql = "SELECT USR_UID FROM LOGIN_LOG WHERE LOG_INIT_DATE >= '$time24mAgo' AND 
      LOG_END_DATE IS NULL AND USR_UID IN ($sMemberIDs)";
   $aLogins = executeQuery($sql); 
   
   foreach ($aLogins as $aLogin) {
       $aLoggedUsers[] = $aLogin['USR_UID'];
   }
 
   //check if any of the users have added anything to the APP_HISTORY in the last 24 minutes: 
   $sqlHistory = "SELECT USR_UID FROM APP_HISTORY 
      WHERE HISTORY_DATE >= '$time24mAgo' AND USR_UID IN ($sMemberIDs)";
   $aHistories = executeQuery($sqlHistory);

   foreach ($aHistories as $aHistory) {
       $aLoggedUsers[] = $aHistory['USR_UID'];
   }

   //check if any of the users have started or routed a case in the last 24 minutes: 
   $sqlDelegation = "SELECT USR_UID FROM APP_DELEGATION 
      WHERE USR_UID IN ($sMemberIDs) AND 
      (DEL_DELEGATE_DATE >= '$time24mAgo' OR DEL_FINISH_DATE >= '$time24mAgo')";
   $aDelegations = executeQuery($sqlDelegation);

   foreach ($aDelegations as $aDelegation) {
       $aLoggedUsers[] = $aDelegation['USR_UID'];
   }
   
   return array_unique($aLoggedUsers);
}       

//skip first task in process if at least one member of the "Users Logged for Task1" group isn't logged in:
if (count(checkIfLogged() == 0) {
   @@nextAssignedUser == @@USER_LOGGED;
   PMFDerivateCase(@@APPLICATION, @%INDEX, @@USER_LOGGED);
}

Set this trigger to fire before the first step in the first task of the process.

This code might require some debug but it gives you the basic idea.
#813097
Thanks for the response, and quick question. Why would the following work, if I had a gateway with these conditions for the user ID?

Code: Select all
@@USER_LOGGED == "6516676265a70d93c27fd97011375811" OR @@USER_LOGGED == "2389842775a70d957cb25c8069430985" OR @@USER_LOGGED == "4780608765a70d96d45e323053103951"

Goes to task 1
Code: Select all
@@USER_LOGGED != "6516676265a70d93c27fd97011375811" OR @@USER_LOGGED != "2389842775a70d957cb25c8069430985" OR @@USER_LOGGED != "4780608765a70d96d45e323053103951"

Goes to task 2
#813107
If you want a gateway like that, then you should use these conditions:
Code: Select all
@@USER_LOGGED == "6516676265a70d93c27fd97011375811" OR @@USER_LOGGED == "2389842775a70d957cb25c8069430985" OR @@USER_LOGGED == "4780608765a70d96d45e323053103951"

Goes to task 1

@@USER_LOGGED != "6516676265a70d93c27fd97011375811" AND @@USER_LOGGED != "2389842775a70d957cb25c8069430985" AND @@USER_LOGGED != "4780608765a70d96d45e323053103951"

Goes to task 2
If you want to immediately skip the first task and go to the gateway, then add this trigger to the first task:
Code: Select all
@@nextAssignedUser = @@USER_LOGGED;
jumping(@@APPLICATION, @%INDEX); 
where the second task has Value Based Assignment and its variable is @@nextAssignedUser.

🚨 Discover the power of Immediate ProAir X1 🚀 📈 W[…]

Mosquito Zapper Reviews

https://www.facebook.com/sammosquitozapper https:[…]

https://www.facebook.com/sammosquitozapper https:[…]

Are you looking for a simple method to import EML […]