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;


No comments:

Post a Comment