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

Moderator: 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 Ryguy2
#822153
Hello,
I have created a dropdown that pulls in users that are a member of a group. You can select your users and it saves them to a secondary variable to be called later if needed.

I want to create an email that somehow references the usernames not their id.

Example:
Dear User ,
Here is a list of users that you have selected for this project. 
If you find that you missed any individuals, please create another request with the same details, selecting the missed individuals.
"[\"5369873045abd1322be2d59020167466\",\"5559692385abd269482a175099689073\"]"

This works in my Dynaform. Is there some sort of trigger I can fire post dynaform to convert this back to a username to get the email to display how I would like it?

Thank you for your help.
User avatar
By amosbatto
#822154
Are you using the variable from a checkgroup?
If so, your trigger would be something like this:
Code: Select all
if (!empty(@=recipients)) {
    $aEmails = array();
    foreach (@=recipients as $userId) {
        $aInfo = userInfo($userId);
        $aEmails = $aInfo['firstname'] .' '. $aInfo['firstname'] .' <'. $aInfo['mail'] .'>';
    }
   //convert from array to string of emails addresses:
   $sEmails = implode(',', $aEmails);
   PMFSendMessage(@@APPLICATION, 'admin@example.com', $sEmails, '', '', 'Subject of email', 'mytemplate.html');
}
By Ryguy2
#822170
I am using a trigger before the dynaform:
Code: Select all
$groupName = "All Users List";
$groupId = PMFGetGroupUID($groupName);
if (empty($groupId)) { 
  throw new Exception("Group '$groupName' doesn't exist."); 
}
$aUsers = PMFGetGroupUsers($groupId);
@=traininggroup_users = array(); 

foreach ($aUsers as $aUser) {
   $fullName = $aUser['USR_FIRSTNAME'] .' '. $aUser['USR_LASTNAME'];
   @=traininggroup_users[] = array($aUser['USR_UID'], $fullName);
   
}
to generate the list in a dropdown, using the data variable field calling @@traininggroup_users
I also have a hidden field that is supposed to save the users: grouptraining_userssaved
Then you can select the users you want from the dropdown.

I have this in my Javascript:
Code: Select all
//make dropdown box a list box
$("#grouptraining_users").getControl()[0].multiple = true
//if showing a second time, get saved selections and apply them to the listbox: 
var vals = $("#grouptraining_userssaved").getValue();
if (vals.trim() != "") {
   var aVals = $.parseJSON(vals);
   var fld = $("#grouptraining_users").getControl()[0]; 
   fld.selectedIndex = -1; //clear current selection

   for (var i = 0; i < aVals.length; i++) {
      for (var j = 0; j < fld.options.length; j++) {
         if (aVals[i] == fld.options[j].value)
            fld.options[j].selected = true;
      }
   }
}
//change event handler for listbox to copy selected values into an array and save it in the hidden field
$("#grouptraining_users").getControl().change(function() {
   var aVals = [];
    
   for (var i = 0; i < this.options.length; i++) {
      if (this.options[i].selected)
         aVals.push(this.options[i].value);
   }
   $("#grouptraining_userssaved").setValue(JSON.stringify(aVals));
} );
When I insert either variable into an email or look at the table all I see is the user guid.

Hopefully that makes more sense on what I am doing.

Thank you
User avatar
By amosbatto
#822173
You can create a trigger which fires after that Dynaform which converts from user IDs to their emails, like this:
Code: Select all
if (!empty(@@grouptraining_userssaved)) {
   $aUserIds = json_decode(@@grouptraining_userssaved);
   $aEmails = array();
    foreach (@=recipients as $userId) {
        $aInfo = userInfo($userId);
        $aEmails = $aInfo['firstname'] .' '. $aInfo['firstname'] .' <'. $aInfo['mail'] .'>';
    }
   //convert from array to string of emails addresses:
   $sEmails = implode(',', $aEmails);
   PMFSendMessage(@@APPLICATION, 'admin@example.com', $sEmails, '', '', 'Subject of email', 'mytemplate.html');
}
By Ryguy2
#822179
I don't want to send an email to the list of users, I just want their names to display in an email.
The email will go to the originator of the case to verify that they selected the correct user. I would imagine I could use the trigger and somehow use the trigger to update the template?

Thank you again for your help.
User avatar
By amosbatto
#822188
If that is what you want, then change your trigger before the Dynaform to this:
Code: Select all
$groupName = "All Users List";
$groupId = PMFGetGroupUID($groupName);
if (empty($groupId)) { 
   throw new Exception("Group '$groupName' doesn't exist."); 
}
$aUsers = PMFGetGroupUsers($groupId);
@=traininggroup_users = array(); 

foreach ($aUsers as $aUser) {
   $fullName = $aUser['USR_FIRSTNAME'] .' '. $aUser['USR_LASTNAME'];
   $email = $fullName .' <'. $aUser['USR_EMAIL'] .'>';
   @=traininggroup_users[] = array($email, $fullName);   
}
Now the values of the options in the dropdown will contain the emails.

Then, if you want to convert the JSON string in a normal string, the trigger after the Dynaform can be:
Code: Select all
if (!empty(@@grouptraining_userssaved)) {
   $aUsers = json_decode(@@grouptraining_userssaved);
   @@grouptraining_userlist = implode("<br>\n", $aUsers);
} 
Then you can put @#grouptraining_userlist in the template file for your email.
By Ryguy2
#822594
Thank you again for your help. This was what I needed to get this in place.
Is there a way to get this to sort alphabetically? I have been trying different commands and I cannot seem to get this to do what I want. The list just keeps showing up in a random order.

Thank you again
User avatar
By amosbatto
#822598
You can use the sort() function like this:
Code: Select all
if (!empty(@@grouptraining_userssaved)) {
   $aUsers = json_decode(@@grouptraining_userssaved);
   sort($aUsers);
   @@grouptraining_userlist = implode("<br>\n", $aUsers);
} 
By Ryguy2
#822629
Ok that looks like it will work for the email part.
Is there a way to get the dropdown list to sort as well?
We are importing a bunch of people into the list and it would be nice to have them sorted.

Thank you again.
User avatar
By amosbatto
#822632
The trigger to sort the emails would be:
Code: Select all
$groupName = "All Users List";
$groupId = PMFGetGroupUID($groupName);
if (empty($groupId)) { 
   throw new Exception("Group '$groupName' doesn't exist."); 
}
$aUsers = PMFGetGroupUsers($groupId);
$aUsersList = array(); 

foreach ($aUsers as $aUser) {
   $aUsersList[] = $aUser['USR_FIRSTNAME'] .' '. $aUser['USR_LASTNAME'] .' <'. $aUser['USR_EMAIL'] .'>';
}

sort($aUsersList);
@=traininggroup_users = array();

foreach ($aUsersList as $userEmail) {
    @=traininggroup_users[] = array($userEmail, $userEmail);
}
By Ryguy2
#828971
Hello,

I am trying to use this trigger once again to send emails to each person that is selected in the dropdown list. It appears that the list is Generating unsorted.
PreDynaform:
Trigger for Generating Drop down list:
$groupName = "All Users List";
$groupId = PMFGetGroupUID($groupName);
if (empty($groupId)) {
throw new Exception("Group '$groupName' doesn't exist.");
}
$aUsers = PMFGetGroupUsers($groupId);
@=greatjob_array = array();

foreach ($aUsers as $aUser) {
$fullName = $aUser['USR_FIRSTNAME'] .' '. $aUser['USR_LASTNAME'];
@=greatjob_array[] = array($aUser['USR_UID'], $fullName);

}

It looks like it passes the variables to the hidden field. When I continue it fails to email and the logs shows invalid email.\
Post Dynaform:
if (!empty(@@greatjob_hidden)) {
$aUserIds = json_decode(@@greatjob_hidden);
$aEmails = array();
foreach (@=recipients as $userId) {
$aInfo = userInfo($userId);
$aEmails = $aInfo['firstname'] .' '. $aInfo['firstname'] .' <'. $aInfo['mail'] .'>';
}
//convert from array to string of emails addresses:
$sEmails = implode(',', $aEmails);
PMFSendMessage(@@APPLICATION, 'sample@email.com', $sEmails, '', '', 'Subject of email', 'greatjob.html');
}

So, my 2 problems are I would like the first dynaform to sort.( When I have tried to sort it breaks pulling in the userID, and my email isn't being sent. It is just showing invalid Email Address in the Email Log. I am running 3.5.4-community.

My other process that I originally posted on this populates the names for the email, this process I want to Email based on the names picked.

Thank you all for your help!
By kimberlykeller
#828974
If you are looking for <a href="https://scholaron.com/homework-answers/find-the-p-value-for-the-1413654">Find The P Value For The</a> the best place to get it would be ScholarOn. All questions including <a href="https://scholaron.com/homework-answers/find-the-relative-risk-113-if-1413680">Find The Relative Risk 113 If</a> are listed with complete solutions with exclusive offers on problems like <a href="https://scholaron.com/homework-answers/health-literacy-multiple-choice-1advertisers-shape-1418685">Health Literacy Multiple Choice 1advertisers Shape</a>, all under a single subscription.

Hơn 20 năm kinh nghiệm cùng đội ngũ nh&acir[…]

Get case history

Hi, See attached process example, it makes a cop[…]

Kho đông lạnh

Kho đông lạnh có vai trò quan […]

Como seria possivel migrar todo o workspace de um […]