Sunday 8 September 2024

CI Peoplecode to update Student Name

 /* ===>

This is a dynamically generated PeopleCode template to be used only as a helper

to the application developer.

You need to replace all references to '[*]' OR default values with  references to

PeopleCode variables and/or a Rec.Fields. */

Local File &fileLog;

Local ApiObject &oSession, &oCiPersonalData;

Local ApiObject &oCollNameTypeVwCollection, &oCollNameTypeVw;

Local ApiObject &oCollNamesCollection, &oCollNames;


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;

      Error MsgGet(&oPSMessage.MessageSetNumber, &oPSMessage.MessageNumber, &sErrMsgText);

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

   End-For;

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

   &oPSMessageCollection.DeleteAll();

End-Function;




Function UpdatePersonalData(&EmplId As string, &NameType As string, &EffDate As date, &CountryFormat As string, &LastName As string, &FirstName As string, &MiddleName As string, &SecondLastName As string) Returns boolean

   Local number &WorkAround;

   Local integer &CollCount1, &NameCount;

   

   

   try

      /* Initialize session */

      &oSession = %Session;

      &oSession.PSMessagesMode = 1;

      

      /* Get the Component Interface */

      &oCiPersonalData = &oSession.GetCompIntfc(CompIntfc.CI_PERSONAL_DATA);

      If &oCiPersonalData = Null Then

         errorHandler();

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

      End-If;

      

      /* Set Component Interface Mode */

      &oCiPersonalData.InteractiveMode = True;

      &oCiPersonalData.GetHistoryItems = True;

      &oCiPersonalData.EditHistoryItems = True;

      

      /* Set Component Interface Get/Create Keys */

      &oCiPersonalData.KEYPROP_EMPLID = &EmplId;

      

      /* Execute Get */

      If Not &oCiPersonalData.Get() Then

         errorHandler();

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

      End-If;

      

      /* Set/Get COLL_NAME_TYPE_VW Collection Field Properties */

      &oCollNameTypeVwCollection = &oCiPersonalData.COLL_NAME_TYPE_VW;

      &oCollNameTypeVw = &oCollNameTypeVwCollection.insertitem(&oCollNameTypeVwCollection.count);

      &WorkAround = &oCollNameTypeVw.itemnum;

      &CollCount1 = &oCollNameTypeVwCollection.count;

      &oCollNameTypeVw = &oCollNameTypeVwCollection.Item(&CollCount1);

      &oCollNameTypeVw.KEYPROP_NAME_TYPE = &NameType;

      

      /* Set Names */

      &oCollNamesCollection = &oCollNameTypeVw.COLL_NAMES;

      &NameCount = 0;

      Local integer &i122;

      For &i122 = 1 To 1

         &NameCount = &NameCount + 1;

         If &NameCount > 1 Then

            &oCollNames = &oCollNamesCollection.insertitem(&oCollNamesCollection.count);

            &WorkAround = &oCollNames.itemnum;

         End-If;

         

         &CollCount1 = &oCollNamesCollection.count;

         &oCollNames = &oCollNamesCollection.Item(&CollCount1);

         &oCollNames.KEYPROP_NAME_TYPE = &NameType;

         &oCollNames.KEYPROP_EFFDT = &EffDate;

         &oCollNames.PROP_COUNTRY_NM_FORMAT = &CountryFormat;

         &oCollNames.PROP_NAME_PREFIX = "";

         &oCollNames.PROP_NAME_SUFFIX = "";

         &oCollNames.PROP_LAST_NAME = &LastName;

         &oCollNames.PROP_FIRST_NAME = &FirstName;

         &oCollNames.PROP_MIDDLE_NAME = &MiddleName;

         &oCollNames.PROP_SECOND_LAST_NAME = &SecondLastName;

      End-For;

      

      /* Execute Save */

      If Not &oCiPersonalData.Save() Then

         errorHandler();

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

      End-If;

      

      /* Execute Cancel */

      If Not &oCiPersonalData.Cancel() Then

         errorHandler();

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

      End-If;

      

      /* Return True if successful */

      Return True;

      

   catch Exception &ex1

      Error MsgGet(0, 0, "Caught exception: " | &ex1.ToString());

      /* Return False if an error occurs */

      Return False;

   end-try;

   

End-Function;


Local boolean &isSuccessful;


&SQL1 = CreateSQL("select distinct emplid ,initcap(last_name) , initcap(first_name) ,initcap(middle_name) ,initcap(second_last_name) from ps_uod_name_load WHERE descr = 'rr' and ROWNUM <= 400");


While &SQL1.Fetch(&emplid, &LastName, &FirstName, &MiddleName, &SecondLastName)

   

   &isSuccessful = UpdatePersonalData(&emplid, "PRI", %Date, "001", &LastName, &FirstName, &MiddleName, &SecondLastName);

   

   If &isSuccessful Then

      

      SQLExec("update ps_uod_name_load set descr='true' where emplid =:1", &emplid);

      rem   MessageBox(0, "", 0, 0, "Update was successful.");

      

   Else

      rem MessageBox(0, "", 0, 0, "Update failed.");

      SQLExec("update ps_uod_name_load set descr='false' where emplid =:1 ", &emplid);

   End-If;

   

End-While;


Monday 2 September 2024

Code to delete term activation using peoplecode - component interface

 

/* ===>

This is a dynamically generated PeopleCode template to be used only as a helper

to the application developer.

You need to replace all references to '[*]' OR default values with references to

PeopleCode variables and/or a Rec.Fields. */


Local File &fileLog;

Local ApiObject &oSession, &oTermActivationCi;

Local ApiObject &oStdntCareerCollection, &oStdntCareer;

Local ApiObject &oStdntCarTermCollection, &oStdntCarTerm;

Local boolean &result;


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;


Function ProcessTermActivation(&emplid As string, &strm As string) Returns boolean

   

   &fileLog = GetFile("C:\Users\mmlatif\AppData\Local\Temp\TERM_ACTIVATION_CI.log", "w", "a", %FilePath_Absolute);

   &fileLog.WriteLine("Begin");

   

   

   &result = False; /* Initialize the result as False */

   

   try

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

      &oSession = %Session;

      

      rem ***** Set the PeopleSoft Session Error Message Mode *****;

      &oSession.PSMessagesMode = 1;

      

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

      &oTermActivationCi = &oSession.GetCompIntfc(CompIntfc.TERM_ACTIVATION_CI);

      If &oTermActivationCi = Null Then

         errorHandler();

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

      End-If;

      

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

      &oTermActivationCi.InteractiveMode = False;

      &oTermActivationCi.GetHistoryItems = True;

      &oTermActivationCi.EditHistoryItems = False;

      

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

      &oTermActivationCi.EMPLID = &emplid;

      

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

      If Not &oTermActivationCi.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 *****;

      &oStdntCareerCollection = &oTermActivationCi.STDNT_CAREER;

      Local integer &i132;

      For &i132 = &oStdntCareerCollection.Count To 1 Step - 1

         &oStdntCareer = &oStdntCareerCollection.Item(&i132);

         

         rem ***** Set STDNT_CAR_TERM Collection Field Properties -- Parent: STDNT_CAREER Collection *****;

         &oStdntCarTermCollection = &oStdntCareer.STDNT_CAR_TERM;

         Local integer &i235;

         For &i235 = &oStdntCarTermCollection.Count To 1 Step - 1

            &oStdntCarTerm = &oStdntCarTermCollection.Item(&i235);

            If &oStdntCarTerm.STRM = &strm Then

               rem ***** Delete the row with the specified STRM *****;

               &oStdntCarTermCollection.DeleteItem(&i235);

            End-If;

         End-For;

      End-For;

      

      rem ***** Save the changes *****;

      If Not &oTermActivationCi.Save() Then

         errorHandler();

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

      End-If;

      

      rem ***** Cancel the CI (cleanup) *****;

      If Not &oTermActivationCi.Cancel() Then

         errorHandler();

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

      End-If;

      

      &result = True; /* If all steps succeed, set the result to True */

      

   catch Exception &ex

      

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

      

      

      &result = False; /* Ensure the result remains False if any exception is thrown */

   end-try;

   

   Return &result;

End-Function;


&SQL1 = CreateSQL("select distinct emplid  from PS_UOD_STDDEL_TERM ");


While &SQL1.Fetch(&emplid)

   

   Local boolean &isSuccess;

   &isSuccess = ProcessTermActivation(&emplid, "2241");

   

   If &isSuccess Then

      

      

      &fileLog.WriteLine("Term Activation processed successfully.");

      REM MessageBox(0, "", 0, 0, "Term Activation processed successfully.");

   Else

      &fileLog.WriteLine("Failed to process Term Activation.");

      

      REM MessageBox(0, "", 0, 0, "Failed to process Term Activation.");

   End-If;

   

End-While;