Monday, 14 July 2025

Add Student Name using CI in Peoplecode

 

Component Name : NAMES_OTHER 


Global string &FileName, &APPLIED_TERM;

Global string &PROCESS_INSTANCE;

Global string &RUN_CNTL_ID;

Global string &Type;

Local SQL &StudentList;

Local string &SQLquery;

Global ApiObject &oSession, &oNamesCi;


Global File &LogFile;


Function errorHandler()

   Local ApiObject &oPSMessageCollection, &oPSMessage;

   Local number &i;

   Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;

   

   &oPSMessageCollection = &oSession.PSMessages;

   For &i = 1 To &oPSMessageCollection.Count

      &oPSMessage = &oPSMessageCollection.Item(&i);

      &sErrMsgSetNum = &oPSMessage.MessageSetNumber;

      &sErrMsgNum = &oPSMessage.MessageNumber;

      &sErrMsgText = &oPSMessage.Text;

      MessageBox(0, "", 0, 0, (&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText));

   End-For;

   rem ***** Delete the Messages from the collection *****;

   &oPSMessageCollection.DeleteAll();

End-Function;


&APPLIED_TERM = ITS_POSTPRC_AET.STRM.Value;

&StudentList = CreateSQL(SQL.ITS_GET_ARA_NAMES_DATA, &APPLIED_TERM);

While &StudentList.Fetch(&EMPLID, &FIRST_NAME_ARB, &MIDDLE_NAME_ARB, &SECOND_LAST_NM_ARB, &LAST_NAME_ARB)

   

   try

      rem ***** Get current PeopleSoft Session *****;

      &oSession = %Session;

      

      rem ***** Get the Component Interface for Each Student *****;

      &oNamesCi = &oSession.GetCompIntfc(CompIntfc.NAMES_CI);

      If &oNamesCi = Null Then

         errorHandler();

         throw CreateException(0, 0, "GetCompIntfc failed for EMPLID: " | &EMPLID);

      End-If;

      

      rem ***** Set Component Interface Properties *****;

      &oNamesCi.InteractiveMode = True;

      &oNamesCi.GetHistoryItems = True;

      &oNamesCi.EditHistoryItems = True;

      

      rem ***** Set CI Keys *****;

      &oNamesCi.EMPLID = &EMPLID;

      

      rem ***** Execute Get *****;

      If Not &oNamesCi.Get() Then

         errorHandler();

         throw CreateException(0, 0, "Get failed for EMPLID: " | &EMPLID);

      End-If;

      

      rem ***** Process NAME_TYPE_VW Collection *****;

      &oNameTypeVwCollection = &oNamesCi.NAME_TYPE_VW;

      &oNameTypeVw = &oNameTypeVwCollection.Item(1); 

      

      rem ***** Process NAMES Collection *****;

      &oNamesCollection = &oNameTypeVw.NAMES;

      &oNames = &oNamesCollection.InsertItem(1);

      

      &oNames.NAME_TYPE = "OTH";

      &oNames.EFFDT = %Date;

      &oNames.EFF_STATUS_0 = "A";

      &oNames.COUNTRY_NM_FORMAT = "ARA";

      &oNames.LAST_NAME = &LAST_NAME_ARB;

      &oNames.FIRST_NAME = &FIRST_NAME_ARB;

      &oNames.MIDDLE_NAME = &MIDDLE_NAME_ARB;

      &oNames.SECOND_LAST_NAME = &SECOND_LAST_NM_ARB;

      

      rem ***** Execute Save *****;

      If Not &oNamesCi.Save() Then

         errorHandler();

         throw CreateException(0, 0, "Save failed for EMPLID: " | &EMPLID);

      Else

         &LogFile.WriteLine("Arabic name has been updated successfully for student " | &EMPLID);

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

         SQLExec("COMMIT");

         

      End-If;

      

      rem ***** Execute Cancel *****;

      If Not &oNamesCi.Cancel() Then

         errorHandler();

         throw CreateException(0, 0, "Cancel failed for EMPLID: " | &EMPLID);

      End-If;

      

      rem ***** Release Component Interface *****;

      &oNamesCi = Null;

      REM   End-If;

   catch Exception &ex

      rem Log the exception for debugging;

      MessageBox(0, "", 0, 0, "Error for EMPLID: " | &EMPLID | " - " | &ex.ToString());

      &LogFile.WriteLine("Error updating Arabic name for student " | &EMPLID | ": " | &ex.ToString());

   end-try;

   

End-While;


Sunday, 13 July 2025

Assig Student groups to student using CI in Peoplecode

 


Local File &fileLog;

Local ApiObject &oSession, &oUodaStdntGroupsPersCi;

Local ApiObject &oPersnlFerpaVwCollection, &oPersnlFerpaVw;

Local ApiObject &oSrvcIndSelVwCollection, &oSrvcIndSelVw;

Local ApiObject &oStdntGrpsCollection, &oStdntGrps;

Local ApiObject &oStdntGrpsHistCollection, &oStdntGrpsHist;


Function errorHandler()

   Local ApiObject &oPSMessageCollection, &oPSMessage;

   Local number &i;

   Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;

   

   &oPSMessageCollection = &oSession.PSMessages;

   For &i = 1 To &oPSMessageCollection.Count

      &oPSMessage = &oPSMessageCollection.Item(&i);

      &sErrMsgSetNum = &oPSMessage.MessageSetNumber;

      &sErrMsgNum = &oPSMessage.MessageNumber;

      &sErrMsgText = &oPSMessage.Text;

      rem &fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);

   End-For;

   rem ***** Delete the Messages from the collection *****;

   &oPSMessageCollection.DeleteAll();

End-Function;


try


   &oSession = %Session;

   


   &oSession.PSMessagesMode = 1;

   

   rem ***** Get the Component Interface *****;

   &oUodaStdntGroupsPersCi = &oSession.GetCompIntfc(CompIntfc.X_STDNT_GROUPS_PERS_CI);

   If &oUodaStdntGroupsPersCi = Null Then

      errorHandler();

      throw CreateException(0, 0, "GetCompIntfc failed");

   End-If;

   

   rem ***** Set the Component Interface Mode *****;

   &oUodaStdntGroupsPersCi.InteractiveMode = False;

   &oUodaStdntGroupsPersCi.GetHistoryItems = True;

   &oUodaStdntGroupsPersCi.EditHistoryItems = False;

   

   rem ***** Set Component Interface Get/Create Keys *****;

   &oUodaStdntGroupsPersCi.EMPLID = "2250030300";

   

   rem ***** Execute Get *****;

   If Not &oUodaStdntGroupsPersCi.Get() Then

      rem ***** No rows exist for the specified keys.*****;

      errorHandler();

      throw CreateException(0, 0, "Get failed");

   End-If;

   

   

   rem ***** Begin: Get/Set Component Interface Properties *****;

   

   

   

   rem ***** Set/Get STDNT_GRPS Collection Field Properties -- Parent: PS_ROOT Collection *****;

   &oStdntGrpsCollection = &oUodaStdntGroupsPersCi.STDNT_GRPS;

   Local integer &i121;

   rem For &i121 = 1 To &oStdntGrpsCollection.Count;

   &oStdntGrps = &oStdntGrpsCollection.insertItem(1);

   

   &oStdntGrps.INSTITUTION = "UABC";

   &oStdntGrps.STDNT_GROUP = "W001";

   

   rem ***** Set STDNT_GRPS_HIST Collection Field Properties -- Parent: STDNT_GRPS Collection *****;

   &oStdntGrpsHistCollection = &oStdntGrps.STDNT_GRPS_HIST;

   Local integer &i224;

   rem  For &i224 = 1 To &oStdntGrpsHistCollection.Count;

   &oStdntGrpsHist = &oStdntGrpsHistCollection.Item(1);

   

   &oStdntGrpsHist.EFFDT = %Date;

   &oStdntGrpsHist.EFF_STATUS = "A";

   rem    End-For;

   rem   End-For;

   rem ***** End: Get/Set Component Interface Properties *****;

   

   rem ***** Execute Save *****;

   If Not &oUodaStdntGroupsPersCi.Save() Then;

      throw CreateException(0, 0, "Save failed");

   End-If;

   

   rem ***** Execute Cancel *****;

   If Not &oUodaStdntGroupsPersCi.Cancel() Then;

      errorHandler();

      throw CreateException(0, 0, "Cancel failed");

   End-If;

   

catch Exception &ex

   rem Handle the exception;

   rem &fileLog.WriteLine(&ex.ToString());

   MessageBox(0, "", 0, 0, "" | &ex.ToString());

end-try;

rem &fileLog.WriteLine("End");


Sunday, 6 July 2025

SQL to get Long description of Translate Field

 


SELECT A.X_APP_TYPE   

 , B.XLATLONGNAME   

 , A.X_HP_ENTITYID   

 ,A.X_HP_BEARER   

  FROM PS_X_SIS_APP_KEYS A   

  , PSXLATITEM B   

 WHERE B.FIELDNAME = 'X_APP_TYPE'   

   AND B.FIELDVALUE = A.X_APP_TYPE   

   AND B.EFF_STATUS = 'A'   

   AND ( B.EFFDT = (  

 SELECT MAX(A_ED.EFFDT)   

  FROM PSXLATITEM A_ED   

 WHERE B.FIELDNAME = A_ED.FIELDNAME   

   AND B.FIELDVALUE = A_ED.FIELDVALUE   

   AND A_ED.EFFDT <= SYSDATE))

Radio button-like behavior using checkboxes in a grid

 Following PeopleCode  enforces radio button-like behavior using checkboxes in a grid. When the user checks a checkbox in one row of the grid, it will automatically uncheck all others.


/* Place this code in the FieldChange event of X_SELECT */

Local Rowset &rs;

Local Row &row;

Local integer &rowCount;

/* Get the grid rowset */

&rs = GetLevel0().GetRow(1).GetRowset(Scroll.X_STD_INSTLMNTS);


For &i = 1 To &rs.ActiveRowCount

  

   /* Uncheck all other checkboxes */

   If &i <> CurrentRowNumber() Then

      

      &rs(&i).X_STD_INSTLMNTS.X_SELECT.Value = "N";

   Else

      /* Ensure the clicked row is checked */

      &rs(&i).X_STD_INSTLMNTS.X_SELECT.Value = "Y";

      

   End-If;

End-For;


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);