This is a continuation of the following posts:
- Part 1: Creating the Component Interface
- Part 2: Security
- Part 3: PeopleCode
- Part 4: Handling Errors
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:
1 2 3 4 5 6 | 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; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 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:
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:
So, our field name is BirthCountry. Let’s add the line to set it to all X’s:
Unfortunately, same result:
And, here is all of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | 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.