Email Users Under a Specific Role Name

Your rating: None Average: 5 (4 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)
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_FLAGS = 0;
&MAIL_CC = "";
&MAIL_BCC = "";
&MAIL_FILES = "";
&MAIL_TITLES = "";
/* Getting EMAILID from state record*/
&EMAILID = YOUR_STATE_RECORD.EMAILID;
&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*/
&RET = SendMail(&MAIL_FLAGS, &EMAILID, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT, &MAIL_FILES, &MAIL_TITLES);

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

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!

Comments

Have a question? Please ask it on the forum instead.

Post new comment

CAPTCHA
The question below is to prevent automated spam submissions.
7 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.