Monday, April 29, 2019

Peoplesoft: Add Manager into CC List in Generic Email Template


Open APP designer, EOAW_CORE Application Package, NotificationManager App Class

method Notify
   /+ &from_ as String, +/
   /+ &templateID_ as String, +/
   /+ &aryOpridTo_ as Array of String, +/
   /+ &pageURL_ as String, +/
   /+ &strSQLId_ as String, +/
   /+ &recThread_ as Record +/
   Local array of string &aryValues;
   Local array of PT_WF_NOTIFICATION:NotificationAddress &notifyTo;
   Local string &URL, &XMLVars;
   Local boolean &Status;
   Local PT_WF_NOTIFICATION:NotificationAddress &NotifyAddress;
   Local PT_WF_NOTIFICATION:NotificationTemplate &NotifyTemplate;
   Local PT_WF_NOTIFICATION:Notification &Notification;
   Local integer &i;
   Local string &opridTo, &emailTo, &oprDesc, &lng;
 
   Local array of string &langs = CreateArrayRept("", 0);
   Local number &langIndex;
   Local array of array of PT_WF_NOTIFICATION:NotificationAddress &langNotifyList = CreateArrayRept(CreateArrayRept(&NotifyAddress, 0), 0);
 
   /*Start: Custom Code To Populate CC Value*/
 
   Local array of PT_WF_NOTIFICATION:NotificationAddress &notifyCC;
   Local PT_WF_NOTIFICATION:NotificationAddress &FTNotifyAddressCC;
   Local string &opridCC, &emailCC, &oprDescCC, &lngCC, &SupID;
   Local array of string &langsCC = CreateArrayRept("", 0);
   Local number &langIndexCC;
   Local array of array of PT_WF_NOTIFICATION:NotificationAddress &FTlangNotifyListCC = CreateArrayRept(CreateArrayRept(&FTNotifyAddressCC, 0), 0);
   /*End: Custom Code To Populate CC Value*/
 
   &notifyTo = CreateArrayRept(&NotifyAddress, 0);
 
   For &i = 1 To &aryOpridTo_.Len
      &emailTo = %This.GetEmail(&aryOpridTo_ [&i]);
   
      If (All(&emailTo)) Then
         &oprDesc = %This.GetOprDescr(&aryOpridTo_ [&i], &lng);
         &NotifyAddress = create PT_WF_NOTIFICATION:NotificationAddress(&aryOpridTo_ [&i], &oprDesc, " ", &emailTo, "Email");
         rem Worklist Channel &NotifyAddress = create NotificationAddress(&aryOpridTo_ [&i], " ", " ", &emailTo, "Worklist");
         If (None(&lng)) Then
            &lng = %Language;
         End-If;
         &langIndex = &langs.Find(&lng);
         If (&langIndex > 0) Then
            &langNotifyList [&langIndex].Push(&NotifyAddress);
         Else
            &langs.Push(&lng);
            &notifyTo = CreateArrayRept(&NotifyAddress, 0);
            &notifyTo.Push(&NotifyAddress);
            &langNotifyList.Push(&notifyTo);
         End-If;
      End-If;
   
      /*Start: Custom Code To Populate CC Value*/
     
      &notifyCC = CreateArrayRept(&FTNotifyAddressCC, 0);
     
      For &i = 1 To &aryOpridTo_.Len
       
         rem SQLExec("SELECT OPRID FROM PSUSEREMAIL WHERE PRIMARY_EMAIL = 'Y' AND EMAILID = :1 ", &langNotifyList [&langIndex], &FTApproverOPRID);
         SQLExec("SELECT E.EMAILID,E.OPRID FROM PS_ROLEXLATOPR O,PSUSEREMAIL E WHERE O.ROLEUSER_SUPR=E.OPRID AND E.PRIMARY_EMAIL = 'Y' AND O.OPRID = :1", &aryOpridTo_ [&i], &emailCC, &SupID);
         rem &emailCC = %This.GetEmail(&aryOpridTo_ [&i]);
         If (All(&emailCC)) Then
            &oprDescCC = %This.GetOprDescr(&SupID, &lngCC);
            &FTNotifyAddressCC = create PT_WF_NOTIFICATION:NotificationAddress(&SupID, &oprDescCC, " ", &emailCC, "Email");
            If (None(&lngCC)) Then
               &lngCC = %Language;
            End-If;
            &langIndexCC = &langsCC.Find(&lngCC);
            If (&langIndexCC > 0) Then
               &FTlangNotifyListCC [&langIndexCC].Push(&FTNotifyAddressCC);
            Else
               &langsCC.Push(&lngCC);
               &notifyCC = CreateArrayRept(&FTNotifyAddressCC, 0);
               &notifyCC.Push(&FTNotifyAddressCC);
               &FTlangNotifyListCC.Push(&notifyCC);
            End-If;
         End-If;
       
      End-For;
     
      /*End: Custom Code To Populate CC Value*/
   
   
   
   End-For;
 
   Local number &templateIndex = &templateNames.Find(&templateID_);
   If (&templateIndex = 0) Then
      &NotifyTemplate = create PT_WF_NOTIFICATION:NotificationTemplate(" ", " ", &templateID_, "G");
      &templateNames.Push(&templateID_);
      &templates.Push(&NotifyTemplate);
   Else
      &NotifyTemplate = &templates [&templateIndex];
   End-If;
 
   For &langIndex = 1 To &langs.Len
      %This.currentLanguage = &langs [&langIndex];
      &aryValues = %This.LoadTemplateData(&pageURL_, &strSQLId_, &recThread_);
      &XMLVars = &NotifyTemplate.SetupGenericVars(&aryValues);
      &Status = &NotifyTemplate.GetAndExpandTemplate(%This.currentLanguage, &XMLVars);
      Local string &from = &from_;
      rem = %This.GetEmail(&from_);
      If (&Status) Then
         /* Send */
       
         &Notification = create PT_WF_NOTIFICATION:Notification(&from, %Date + %PerfTime, %Language);
         &Notification.NotifyTo = &langNotifyList [&langIndex];
       
         /*Start: Custom Code To Populate CC Value, You can use your own template name for escalations*/
         If &templateID_ = "Voucher Escalation" Then
           
            &Notification.NotifyCC = &FTlangNotifyListCC [&langIndex];
           
         End-If;
         /*End: Custom Code To Populate CC Value*/
         &Notification.Subject = &NotifyTemplate.Subject;
         &Notification.Message = &NotifyTemplate.Text;
         &Notification.Subject = Substitute(&Notification.Subject, "%NotificationPriority", &NotifyTemplate.Priority);
         &Notification.Message = Substitute(&Notification.Message, "%NotificationPriority", &NotifyTemplate.Priority);
         Evaluate &NotifyTemplate.SenderType
         When = "3" /* "Other" */
            &Notification.EmailReplyTo = &NotifyTemplate.SenderEmailID;
            Break;
         When = "2" /* System */
            &Notification.EmailReplyTo = %SMTPSender;
            Break;
            /* when = "1" is already assumed when the variable is set above */
         End-Evaluate;
       
         /* This property should be on each template to avoid sending all with one content-type */
         &Notification.ContentType = "Content-type: text/html; charset=UTF-8";
         &Notification.Send();
      Else
       
         Local EOAW_CORE:Utils &utils = GetUtilsSingleton();
         Local string &default = "Notification template (id " | &templateID_ | ") could not be expanded.";
         Local string &msg = MsgGetText(&utils.MSG_CATALOG, &utils.MSG_NOTIFICATION_FAILURE, &default, &templateID_);
         Local Exception &base = CreateException(&utils.MSG_CATALOG, &utils.MSG_NOTIFICATION_FAILURE, &default, &templateID_);
         throw create EOAW_CORE:EXCEPTIONS:SACError(&base, &msg);
      End-If;
   End-For;
end-method;