Explorations in Component Interface Revisited

This is a continuation of the following posts:

This time, we are trying some of the suggestions from Dan on this comment:

  • Don’t recreate the Component Interface each time
  • Try multiple errors

So, let’s see what happens

Reusing the Component Interface

In my previous example, my code creates the Component Interface each time:

rem ***** Get the Component Interface *****;
&oBlgPersDtaCi = &oSession.GetCompIntfc(CompIntfc.BLG_PERS_DTA_CI);
If &oBlgPersDtaCi = Null Then
   errorHandler();
   throw CreateException(0, 0, "GetCompIntfc failed");
End-If;
So, I created a new variable:
Code: New Variable
Then, I wrapped it around the component interface create code so that it would only do it once:
Code: If Statement
Unfortunately, everything still runs the same:
Output Log Files
Just so you have it, here is the complete code:
Local File &fileLog;
Local ApiObject &oSession, &oBlgPersDtaCi;
Local string &emplid;
Local boolean &ciCreated;

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;
      &fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);
   End-For;
   rem ***** Delete the Messages from the collection *****;
   &oPSMessageCollection.DeleteAll();
End-Function;

Function updateCI(&emplid As string, &makeError As boolean)
   try

   If Not &ciCreated Then;
      rem ***** Set the PeopleSoft Session Error Message Mode *****;
      rem ***** 0 - None *****;
      rem ***** 1 - PSMessage Collection only (default) *****;
      rem ***** 2 - Message Box only *****;
      rem ***** 3 - Both collection and message box *****;
      &oSession.PSMessagesMode = 1;

      rem ***** Get the Component Interface *****;
      &oBlgPersDtaCi = &oSession.GetCompIntfc(CompIntfc.BLG_PERS_DTA_CI);
      If &oBlgPersDtaCi = Null Then
         errorHandler();
         throw CreateException(0, 0, "GetCompIntfc failed");
      End-If;

      rem ***** Set the Component Interface Mode *****;
      &oBlgPersDtaCi.InteractiveMode = True;
      &oBlgPersDtaCi.GetHistoryItems = True;
      &oBlgPersDtaCi.EditHistoryItems = True;

      &ciCreated = True;
   End-If;

   rem ***** Set Component Interface Get/Create Keys *****;
   &oBlgPersDtaCi.EMPLID = &emplid;

   rem ***** Execute Get *****;
   If Not &oBlgPersDtaCi.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 ***** Get/Set Level 0 Field Properties *****;
   &fileLog.WriteLine("&oBlgPersDtaCi.BIRTHSTATE = " | &oBlgPersDtaCi.BIRTHSTATE);
   If &makeError Then;
      &oBlgPersDtaCi.BIRTHSTATE = "XX";
   Else;
      If &oBlgPersDtaCi.BIRTHSTATE = "TX" Then;
         &oBlgPersDtaCi.BIRTHSTATE = "FL";
      Else;
         &oBlgPersDtaCi.BIRTHSTATE = "TX";
      End-If;
   End-If;
   errorHandler();
   rem ***** End: Get/Set Component Interface Properties *****;
 
   rem ***** Execute Save *****;
   If Not &oBlgPersDtaCi.Save() Then;
      errorHandler();
      throw CreateException(0, 0, "Save failed");
   End-If;

   rem ***** Execute Cancel *****;
   If Not &oBlgPersDtaCi.Cancel() Then;
      errorHandler();
      throw CreateException(0, 0, "Cancel failed");
   End-If;

   catch Exception &ex
      rem Handle the exception;
      &fileLog.WriteLine(&ex.ToString());
   end-try;

End-Function;

&emplid = "KU0001";

rem ***** Set the Log File *****;
&fileLog = GetFile("C:\temp\BLG_PERS_DTA_CI.log", "w", "a", %FilePath_Absolute);
&fileLog.WriteLine("Begin");
rem ***** Get current PeopleSoft Session *****;
&oSession = %Session;
&ciCreated = False;

updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, True);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);
updateCI(&emplid, False);

&fileLog.WriteLine("End");
&fileLog.Close();

Multiple Errors

So, now let’s add a second error.  We are already trying to update the Birth State to an invalid value.  Now, let’s add the Birth Country.  Here is the Online error message we will try to automate:

Birth Country Error Message

One of the first things you should do when you add a new field to your code is to check the mapping.  You can’t assume that the property name of the component interface is the same as the field name on the page.  In this case it is the same though:

Component Interface field mapping

So, our field name is BirthCountry.  Let’s add the line to set it to all X’s:

Code: Setting the Birth Country

Unfortunately, same result:

Output

And, here is all of the code:


Local File &fileLog;

Local ApiObject &oSession, &oBlgPersDtaCi;

Local string &emplid;

Local boolean &ciCreated;

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;

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

End-For;

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

&oPSMessageCollection.DeleteAll();

End-Function;

Function updateCI(&emplid As string, &makeError As boolean)

try

If Not &ciCreated Then;

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

rem ***** 0 - None *****;

rem ***** 1 - PSMessage Collection only (default) *****;

rem ***** 2 - Message Box only *****;

rem ***** 3 - Both collection and message box *****;

&oSession.PSMessagesMode = 1;

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

&oBlgPersDtaCi = &oSession.GetCompIntfc(CompIntfc.BLG_PERS_DTA_CI);

If &oBlgPersDtaCi = Null Then

errorHandler();

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

End-If;

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

&oBlgPersDtaCi.InteractiveMode = True;

&oBlgPersDtaCi.GetHistoryItems = True;

&oBlgPersDtaCi.EditHistoryItems = True;

&ciCreated = True;

End-If;

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

&oBlgPersDtaCi.EMPLID = &emplid;

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

If Not &oBlgPersDtaCi.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 ***** Get/Set Level 0 Field Properties *****;

&fileLog.WriteLine("&oBlgPersDtaCi.BIRTHSTATE = " | &oBlgPersDtaCi.BIRTHSTATE);

If &makeError Then;

&oBlgPersDtaCi.BIRTHCOUNTRY = "XXX";

&oBlgPersDtaCi.BIRTHSTATE = "XX";

Else;

If &oBlgPersDtaCi.BIRTHSTATE = "TX" Then;

&oBlgPersDtaCi.BIRTHSTATE = "FL";

Else;

&oBlgPersDtaCi.BIRTHSTATE = "TX";

End-If;

End-If;

errorHandler();

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

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

If Not &oBlgPersDtaCi.Save() Then;

errorHandler();

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

End-If;

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

If Not &oBlgPersDtaCi.Cancel() Then;

errorHandler();

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

End-If;

catch Exception &ex

rem Handle the exception;

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

end-try;

End-Function;

&emplid = "KU0001";

rem ***** Set the Log File *****;

&fileLog = GetFile("C:\temp\BLG_PERS_DTA_CI.log", "w", "a", %FilePath_Absolute);

&fileLog.WriteLine("Begin");

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

&oSession = %Session;

&ciCreated = False;

updateCI(&emplid, False);

updateCI(&emplid, False);

updateCI(&emplid, False);

updateCI(&emplid, True);

updateCI(&emplid, False);

updateCI(&emplid, False);

updateCI(&emplid, False);

updateCI(&emplid, False);

&fileLog.WriteLine("End");

&fileLog.Close();
<div>

Conclusion

Well, thank you, Dan, for the ideas.  They still didn’t reproduce the problem, but they were a very good attempt.  Maybe someone learned something through the exercises anyway.  Please let me know if anyone else has any ideas.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.