Wednesday, 2 July 2025

Sql.parm Miscount Error in Equations with Callable SQL

 The following occurs when executing an equation engine that uses a callable SQL (with a custom function), or callable SQL contains a custom view 


In Equation Engine, you need to have call parms such that you have 2 more than the number of binds and selected fields - so if you have no binds and
are only returning one field in the select - you would need 3 call parms (1 for sql return code, one for sql row count, one stem to catch the returning
field in your sql). However, if in your select statement in your SQL you use something like a substring function - then the equation will fail when you
test it with an error returned that you don't have the correct number of calls parms.

So, if your sql statement was


SELECT substr(A.STRM,1,2)
FROM ps_session_table


or 

SELECT ITEM_AMT FROM PS_CUSTOM_VW WHERE   EMPLID=:1 AND ADMIT_TERM=:2


You would expect to need 3 bind variables - 2 for sql return codes/row, and a stem to catch the select. However, the equation engine will error your
equation because it is counting each comma in your select as needing a new stem.



The available workaround is to create a TABLE that can be used to simplify the logic of the equation SQL. Insert the data in it and then reference that table instead - using a simpler SQL.

How to Update/Insert on Page Activation

 

Using Begin/End in the SQLExec will get you past the normal PT limitation.



   SQLExec("BEGIN UPDATE PS_PTIAUSERTGTSELS SET DBNAME = '" | &dbName | "' WHERE USERID ='" | %UserId | "'; END;");



     SQLExec("BEGIN INSERT INTO PS_PTIAUSERTGTSELS(USERID, DBNAME) VALUES ('" | %UserId | "', '" | &dbName | "'); END;");

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;