Email Users Under a Specific Role Name

Your rating: None Average: 4.2 (5 votes)

Here is a quick Application Engine section that looks up user's email addresses under a certain ROLE and sends an email notification regarding, well, what ever you'd like.

send email for a specific role

First, you would need a "Do Select" step to loop through the email addresses (if more than one) and call the PeopleCode step below it to send the email. Your Do Select should have the following SQL:

-- you need to store the email address for the peoplecode step to use and thus the %Select(EMAILID).
-- Also, notice that i'm passing in the ROLENAME as a variable.
SELECT emailid
FROM psoprdefn
, psrolemember
WHERE rolename = %Bind(ROLENAME)
AND oprid = roleuser
AND emailid <> ' '

The Do Select will keep looping through the rows one at a time until all rows have been processed.

Now, you need a PeopleCode step after the Do Select to send the email (see picture above) for each user under your targeted role.

&MAIL_CC = "";
&MAIL_BCC = "";
/* Getting EMAILID from state record*/
&MAIL_SUBJECT = MsgGetText(50110, 2, "File Error.");
/*Using MsgGetExplainText function to get the email body text that I've stored in message catalog 50110, 2.*/
&MAIL_TEXT = MsgGetExplainText(50110, 2 "File Error.");
/*calling send SendMail function*/

/*Check for errors*/
if not (&RET = 0) then
   /*Your error processing here*/

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!