Sending Email Notifications using SetLanguage( )
The PeopleSoft system does not translate email content when sending email. However you can use predefined text in the message catalog or Notification templates to accommodate different languages. Using the SetLanguage( ) PeopleCode function enables the system to read the user profile language preference of the intended recipient and send an email in that user’s preferred language.
If there are multiple recipients with different language preferences, then individual emails can be sent to each recipient using a loop around the SetLanguage( ) and TriggerBusinessEvent ( ) function calls. The same method can be applied to SendMail.
As an example, assuming the TO field is a Role mapped to a field SEND_TO_ROLE without route control, you can make the following changes:
To send email notifications using SetLanguage( ):
-
Change the field map for the TO field in Activity email routing to Roleuser by Oprid Qry or Roleuser by Roleuser Qry.
-
Map the bind variable to a field on the page (the value of which will be formatted at runtime in PeopleCode).
For this example, assume the field to be RECEIVER_ID. It can be a field of a derived/work record.
-
In the event for which the TriggerBusinessEvent, or SendMail, is called, use the following code as a model, and modify the emphasized variables:
Local Rowset &ROLE_USER; /* 1. Retrieve the TO user list */ /* Create a rowset to retrieve all users for the role */ &ROLE_USER = CreateRowset(Record.ROLEUSER_VW); &ROLE_USER.Fill("where ROLENAME= :1", SEND_TO_ROLE); /* Loop through user list to send email in their language code */ For &i = 1 To &ROLE_USER.ActiveRowCountRECEIVER_ID = &ROLE_USER(&i).ROLEUSER_VW.OPRID.Value; /* 2. Get the user language code and set the language code*/ SQLExec("Select LANGUAGE_CD FROM PSOPRDEFN where OPRID = :1", &OPRID, &LAN_CD); &temp = SetLanguage(&LAN_CD); /* check return code &temp for error .....*/ /* 3. Retrieve text from message catalog for the language code */ &subject = MsgGetText(msg_set, msg_num_subject, ""); &text = MsgGetText(msg_set, msg_num_text, ""); /*..... Format fields mapped in email route for translation .....*/ /* RECORD.FIELD_SUBJECT.Value = &subject; */ /* RECORD.FIELD_TEXT.Value = &text; */ /* 4. Call TriggerBusinessEvent or SendMail to send email */ &temp = TriggerBusinessEvent(BusProcess."bus_proc_name", BusActivity."activity_name", BusEvent."event_name"); /* &temp = SendMail(0, RECEIVER_ID, "", "", &subject, &text); */ End-For; /* 5. Set language code back to current user */ SQLExec("Select LANGUAGE_CD FROM PSOPRDEFN where OPRID = :1", %OperatorId,⇒ &ORIGINAL_LANGCD); &temp = SetLanguage(&ORIGINAL_LANGCD); /*..... Or &temp = SetLanguage(%Language).....*/ %OperatorId, &ORIGINAL_LANGCD); &temp = SetLanguage(&ORIGINAL_LANGCD); /*..... Or &temp = SetLanguage(%Language).....*/