Friday, 23 May 2025

Send Email getting template from Generic Template

 


Function ITS_SEND_MAIL(&EMPLID As string, &name As string, &TITLE As string, &SUBJECT As string, &CATALOG_NBR As string, &STRM As string, &Stdemail As string, &crse_id As string, &percentage As number)

   

   /* import the package */

   

   Local array of string &aBindVariables;

   Local array of PT_WF_NOTIFICATION:NotificationAddress &oNotifyTo, &oNotifyCc, &oNotifyBcc;

   Local PT_WF_NOTIFICATION:NotificationAddress &oNotifyAddr, &oCcAddr, &oBccAddr;

   Local PT_WF_NOTIFICATION:Notification &oNotif;

   /* Create an array of to-email ids for the Notification class */

   

   

   &emailsaddress = get_instr_email(&STRM, &crse_id);

   

   &oNotifyTo = CreateArrayRept(&oNotifyAddr, 0);

   &oNotifyCc = CreateArrayRept(&oCcAddr, 0);

   &oNotifyBcc = CreateArrayRept(&oBccAddr, 0);

   rem &sToEmail = "Testing_" | &Stdemail | "test";

   Warning &Stdemail;

   &sToEmail = &Stdemail;

   rem  &sToEmail = "munib776@yahoo.com";

   

   &sCcEmail = "munib776@yahoo.com" | &emailsaddress;

   

   &sBccEmail = "";

   /* NotificationAddress(Oprid, Description, Language, to-email-id, Channel) */

   &oNotifyAddr = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &sToEmail, "Email");

   &oNotifyTo.Push(&oNotifyAddr);

   /* Add CC recipient */

   &oCcAddr = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &sCcEmail, "Email");

   &oNotifyCc.Push(&oCcAddr);

   /* Add BCC recipient */

   &oBccAddr = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &sBccEmail, "Email");

   &oNotifyBcc.Push(&oBccAddr);

   /* instantiate the NotificationTemplate class */

   /* NotificationTemplate(component-name, component-market, Generic-template-name, G = Generic Template) */

   &oGenericTemplate = create PT_WF_NOTIFICATION:NotificationTemplate("", "", "ITS_STD_ABS_NOTF", "G");

   /* create an array of all bind variables */

   &aBindVariables = CreateArrayRept("", 0);

   &aBindVariables.Push(&name);

   &aBindVariables.Push(&EMPLID);

   &aBindVariables.Push(&crse_id);

   &aBindVariables.Push(&TITLE);

   &aBindVariables.Push(&SUBJECT);

   &aBindVariables.Push(&CATALOG_NBR);

   &aBindVariables.Push(&percentage);

   /* use the array of bind variables to populate the generic template */

   &xmlVars = &oGenericTemplate.SetupGenericVars(&aBindVariables);

   &oGenericTemplate.GetAndExpandTemplate(%Language, &xmlVars);

   /* instantiate the Notification class */

   /* Notification(Notify-from-email-id, date-time, language) */

   &oNotif = create PT_WF_NOTIFICATION:Notification("noreply@machs.edu.sa", %Date + %PerfTime, %Language);

   /* set properties */

   &oNotif.ContentType = "Content-type: text/html; charset=US-ASCII";

   &oNotif.NotifyTo = &oNotifyTo;

   &oNotif.NotifyCC = &oNotifyCc;

   &oNotif.NotifyBCC = &oNotifyBcc;

   &oNotif.EmailReplyTo = ""; /* see note 1 */

   &oNotif.Subject = &oGenericTemplate.Subject;

   &oNotif.Message = &oGenericTemplate.Text; /* see note 2 */

   /* send email */

   &oNotif.Send();

End-Function;



Wednesday, 21 May 2025

Post Attachments

 

Global File &LogFile;


Global string &APPLIED_TERM;


Function ProcessAttachmentDetails(&emplid As string, &appliedTerm As string)

   Local SQL &sql;

   Local array of string &attachmentData;

   Local number &rowNum;

   Local string &output;

   Local number &FILE_SEQ = 1;

   Local Record &ApplAtch = CreateRecord(Record.SAD_APPL_ATCH);

   

   &sql = CreateSQL(SQL.ITS_GET_ATTACHMENT_DATA, &appliedTerm, &emplid);

   &ID = &emplid;

   While &sql.Fetch(&emplid, &ACAD_CAREER, &STDNT_CAR_NBR, &ADM_APPL_NBR, &ATTACHSYSFILENAME, &ATTACHUSERFILE, &DESCR254, &ext);

      

      &ApplAtch.EMPLID.Value = &emplid;

      &ApplAtch.ACAD_CAREER.Value = &ACAD_CAREER;

      &ApplAtch.STDNT_CAR_NBR.Value = &STDNT_CAR_NBR;

      &ApplAtch.ADM_APPL_NBR.Value = &ADM_APPL_NBR;

      &ApplAtch.ATTACH_SEQ_NBR.Value = &FILE_SEQ;

      &ApplAtch.ATTACHSYSFILENAME.Value = &ATTACHSYSFILENAME;

      &ApplAtch.ATTACHUSERFILE.Value = &ATTACHUSERFILE;

      /* Populate other required fields */

      &ApplAtch.SCC_DATE.Value = %Date;

      &ApplAtch.DESCR254.Value = &DESCR254;

      &ApplAtch.SCC_ROW_ADD_OPRID.Value = %OperatorId;

      &ApplAtch.SCC_ROW_ADD_DTTM.Value = %Datetime;

      &ApplAtch.SCC_ROW_UPD_OPRID.Value = %OperatorId;

      &ApplAtch.SCC_ROW_UPD_DTTM.Value = %Datetime;

      &ApplAtch.AV_ATCH_TYPE.Value = &ext;

      &ApplAtch.Insert();

      SQLExec("Commit");

      &FILE_SEQ = &FILE_SEQ + 1;

      

      

   End-While;

   

   REM &LogFile.WriteLine("Attachments have been processed successfully for ID: " | &ID);

   

   SQLExec("Update PS_ITS_POSTING_LOG SET ITS_APP_ATCH='P' WHERE EMPLID =:1", &ID);

   SQLExec("COMMIT");

   

   SQLExec("INSERT INTO PS_SAD_ATTACHMENTS (SELECT * FROM PS_ITS_ADM_FATTACH WHERE ATTACHSYSFILENAME IN (SELECT DISTINCT ATTACHSYSFILENAME FROM PS_SAD_APPL_ATCH WHERE EMPLID =:1 MINUS SELECT DISTINCT ATTACHSYSFILENAME FROM PS_SAD_ATTACHMENTS))", &ID);

   SQLExec("Commit");

End-Function;






&APPLIED_TERM = ITS_POSTPRC_AET.STRM.Value;

Local SQL &sql1 = CreateSQL("SELECT EMPLID FROM PS_ITS_POSTING_LOG WHERE ITS_APP_ATCH<>'P' ", &EMPLID);

While &sql1.Fetch(&EMPLID)

   ProcessAttachmentDetails(&EMPLID, &APPLIED_TERM);

End-While;