Error Handling
The session object handles error processing for all the APIs, such as Component Interfaces, the Query API, and so on. From the session object, you can check if there have been any errors.
Note: The exception to this is Subscription PeopleCode. All errors for Subscription PeopleCode get logged to the application message error table.
Error messages include system error messages or messages from the message catalog (a common set of error messages used by all PeopleSoft applications.) For a Component Interface, the session object level errors also contain any text errors that may have occurred from running ExecuteEdits.
On the session object, you can use the following properties to initially check for errors:
ErrorPending indicates whether there are API errors
WarningPending indicates whether there are API warnings
All errors are contained in the PSMessages collection. (The PSMessages property on a Session object returns this collection.)
Each item in this collection is a PSMessage object. A PSMessage object contains information about the specific error that has occurred, such as the explain text for the error, the message set number, and so on. (The type of information depends on the type of error.)
If the error was caused by a Component Interface, a contextual string is attached to the end of the Text property of the PSMessage object. This contextual string contains the exact location of the error, that is, which field in which data collection, on which row, caused the error. This string is also accessible (by itself) using the Source property.
When errors are loaded into the PSMessages collection depends on the type of error. System errors (that is, errors in the connection to the PeopleSoft Session) are logged as they occur. When an API error is logged depends on the API, as some APIs can be run in either interactive mode (meaning errors are logged as they happen) or in non-interactive mode (so errors are logged only when a particular method is run.)
If you are using Visual Basic or another COM environment, the PeopleSoft API system raises a COM exception the first time ErrorPending changes from False to True. It will not raise another exception until the PSMessages collection is cleared, which sets ErrorPending back to False.
Note: If you’ve called an API from an Application Engine program, all errors are also logged in the Application Engine error log tables.
Use the following PeopleCode to display messages from the PSMessage collection:
Local ApiObject &Session, &PSMessages;
&Session = %Session;
&PSMessages = &Session.PSmessages;
If (&Session <> Null ) Then
If &PSMessages.Count > 0 Then
For &i = 1 To &PSMessages.Count
&MsgSetNbr = &PSMessages.Item(&i).MessageSetNumber;
&MsgNbr = &PSMessages.Item(&i).MessageNumber;
MessageBox( 0 , " ", &MsgSetNbr, &MsgNbr, "Message not found");
End-For;
&PSMessages.DeleteAll();
End-If;
End-If;