Sunday, 1 June 2025

Disabling copy paste on an input field Using JavaScript

 

write the following code on the post build of the relevant component 

Following are the names of the fields for which I disabled the copy paste 


UOD_SAT_TEMP_EMAIL_ADDR', 'UOD_SAT_TEMP_EMAIL_ADDR2', 'UOD_SAT_TEMP_PHONE','UOD_SAT_TEMP_PHONE1



Local string &script;


&script = "var intervalId = setInterval(function() {";

&script = &script | "  var fieldIds = ['UOD_SAT_TEMP_EMAIL_ADDR', 'UOD_SAT_TEMP_EMAIL_ADDR2', 'UOD_SAT_TEMP_PHONE','UOD_SAT_TEMP_PHONE1'];"; /* <-- Add all your field IDs here */

&script = &script | "  var allFound = true;";

&script = &script | "  fieldIds.forEach(function(id) {";

&script = &script | "    var field = document.querySelector('#' + id);";

&script = &script | "    if (field) {";

&script = &script | "      ['copy', 'paste', 'cut'].forEach(function(evt) {";

&script = &script | "        field.addEventListener(evt, function(e) { e.preventDefault(); });";

&script = &script | "      });";

&script = &script | "    } else {";

&script = &script | "      allFound = false;";

&script = &script | "    }";

&script = &script | "  });";

&script = &script | "  if (allFound) { clearInterval(intervalId); }";

&script = &script | "}, 500);"; /* retry until all fields are found */


AddOnLoadScript(&script);



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;


Monday, 10 March 2025

Do you want to save your changes? Click Yes to go back and save, No to discard your changes.

 

I have two components. I am transferring data from the first component to the second component using transfer code. In the second component, there is a button labeled "RETURN BACK." When I click this button, the transfer code is executed to return to the first component. However, when I click the "RETURN BACK" button, a message is displayed: "Do you want to save your changes? Click Yes to save and go back, or No to discard your changes." This happens even though the data has already been saved.




In order to avoid this, I used the peoplecode  SetSaveWarningFilter( True) .


Calling SetSaveWarningFilter with True input parameter causes the subsequent page to ignore the SaveWarning.



Friday, 7 March 2025

Function to verify if Input data is in Arabic

 

Function IsPureArabic(&input As string) Returns boolean

   Local string &pattern = "[\u0600-\u06FF]+";

   If Find(&pattern, &input) = 1 Then

      Return True;

   Else

      Return False;

   End-If;

End-Function;

Generate and Verify OTP

 Function GenerateAndSaveOTP(&type As string, &mobOrEmail As string, &nationalId As string) Returns integer

   Local number &randomNum;

   Local datetime &currentTime;

   Local SQL &sql;

   Local number &secs;

   Local string &oprid;

   Local number &expireLimitSec = 120;

   /* Get the current user ID and timestamp */

   &oprid = &nationalId;

   &currentTime = %Datetime;

   

   /* Check if an OTP was generated within the last 60 seconds for this user */

   SQLExec("SELECT NVL((SYSDATE - CAST(DATETIME1 AS DATE)) * 86400, 0) AS SECONDS_DIFF FROM PS_T_OTP_SESSIONS WHERE NATIONAL_ID = :1 AND T_TYPE=:2 AND T_MOB_EMAIL=:3", &oprid, &type, &mobOrEmail, &secs);

   

   rem  MessageBox(0, "", 0, 0, "" | &secs);

   If &secs > 0 And

         &secs <= &expireLimitSec Then

      /* OTP is still valid within the last 60 seconds */

      rem MessageBox(0, "", 0, 0, "Please try again after one minute. Your current OTP is still valid.");

      Return 0;

   End-If;

   

   /* Generate a new random OTP between 1000 and 9999 */

   &randomNum = Round((Rand() * 8999) + 1000, 0);

   

   /* Delete any previous OTP for the user */

   rem SQLExec("DELETE FROM PS_T_OTP_SESSIONS WHERE NATIONAL_ID = :1 AND T_TYPE=:2", &oprid, &type);

   SQLExec("DELETE FROM PS_T_OTP_SESSIONS WHERE ((NATIONAL_ID = :1 AND T_TYPE=:2) OR NVL((SYSDATE - CAST(DATETIME1 AS DATE)) * 86400, 0)>:3)", &oprid, &type, &expireLimitSec);

   

   /* Insert the new OTP and current timestamp into the table */

   SQLExec("INSERT INTO PS_T_OTP_SESSIONS (NATIONAL_ID, T_OTP, DATETIME1,T_TYPE,T_MOB_EMAIL) VALUES (:1, :2, :3,:4,:5)", &oprid, &randomNum, &currentTime, &type, &mobOrEmail);

   CommitWork();

   /* Return the newly generated OTP */

   Return &randomNum;

End-Function;


Function VerifyOTP(&type As string, &nationalId As string, &mobOrEmail As string, &inputOTP As number) Returns boolean

   Local string &oprid;

   Local number &secs;

   Local SQL &sql;

   

   /* Get the current user ID */

   &oprid = &nationalId;

   

   /* Retrieve the time difference in seconds if the OTP matches */

   SQLExec("SELECT NVL((SYSDATE - CAST(DATETIME1 AS DATE)) * 86400, 0) AS SECONDS_DIFF FROM PS_T_OTP_SESSIONS WHERE NATIONAL_ID = :1 AND T_OTP = :2 AND T_TYPE=:3 AND T_MOB_EMAIL=:4", &oprid, &inputOTP, &type, &mobOrEmail, &secs);

   

   /* Check if OTP exists and is within the valid time period */

   If &secs > 0 And

         &secs < 120 Then

      /* OTP is valid, so delete it after verification */

      rem SQLExec("DELETE FROM PS_T_OTP_SESSIONS WHERE NATIONAL_ID = :1", &oprid);

      rem CommitWork();

      Return True; /* OTP verified successfully */

   Else

      /* OTP is invalid or expired */

      Return False;

   End-If;

End-Function;


Function deleteOtpsAfterVerification(&nationalId As string)

   Local string &oprid = &nationalId;

   

   SQLExec("DELETE FROM PS_T_OTP_SESSIONS WHERE NATIONAL_ID = :1", &oprid);

   CommitWork();

End-Function;



Convert the Gregorian date to Hijri

 


Function ConvertToHijri(&gregorianDate As date) Returns string

   Local SQL &sql;

   Local string &hijriDate;

   Local string &oracleDate;

   

   /* Convert PeopleCode date to Oracle-compatible date string (YYYY-MM-DD) */

   &oracleDate = DateTimeToLocalizedString(&gregorianDate, "MM-dd-yyyy");

   

   /* SQL to convert the Gregorian date to Hijri */

   &sql = CreateSQL("      SELECT TO_CHAR(TO_DATE(:1, 'mm-dd-yyyy'), 'mm-dd-yyyy', 'nls_calendar=''Arabic Hijrah''')      FROM DUAL   ", &oracleDate);

   

   /* Fetch the result */

   If &sql.Fetch(&hijriDate) Then

      Return &hijriDate;

   Else

      /* Return an empty string if the conversion fails */

      Return "";

   End-If;

End-Function;