Quantcast
Viewing latest article 3
Browse Latest Browse All 13

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:
Then, I wrapped it around the component interface create code so that it would only do it once:
Unfortunately, everything still runs the same:
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:

Image may be NSFW.
Clik here to view.
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:

Image may be NSFW.
Clik here to view.
Component Interface field mapping

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

Image may be NSFW.
Clik here to view.
Code: Setting the Birth Country

Unfortunately, same result:

Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.
Share


Viewing latest article 3
Browse Latest Browse All 13

Trending Articles