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;


No comments:

Post a Comment