You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

PSMessages Collection - how to write to it without throwing Errors/Warnings?

5 replies [Last post]
Larry's picture
User offline. Last seen 2 years 31 weeks ago. Offline
Joined: 03/18/2008
Posts: 19

Hi again!

Need to understand how to write to the PSMessages collection without actually throwing Errors/Warnings in Peoplecode. Is there a way to do this?

I've got an App that uses Rowset processing and various Edit flags to trap/process errors without actually throwing any Error() or Warning() statements. Basically I'm just displaying them on an "Errors" page within the same Component, synched up to the primary data page in the same component.

However since my new logic doesn't actually fire an Error() or Warning() statement, the errors are not written to the PSMessages collection, which has become an issue w/ me.

Any ideas?

Lepa's picture
User offline. Last seen 1 year 31 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: PSMessages Collection - how to write without throwing Errors

Yes there is Larry, here is a function that I have developed that does exactly that:

Function CheckSessionMessages(&bDisplayErrors As boolean) Returns number;
   
   Local ApiObject &PSMessages;
   Local number &i, &MsgSetNbr, &MsgNbr, &NbrErrors;
   
   /*get only error messages*/
   %Session.PSMessagesMode = %PSMessages_CollectionOnly;
   &PSMessages = %Session.PSmessages;
   &NbrErrors = &PSMessages.Count;
   
   If &NbrErrors > 0 Then
      For &i = 1 To &NbrErrors
         &MsgSetNbr = &PSMessages.Item(&i).MessageSetNumber;
         &MsgNbr = &PSMessages.Item(&i).MessageNumber;
         /* MessageBox(0, "", &MsgSetNbr, &MsgNbr, "Message Not Found : " | &MsgSetNbr | "," | &MsgNbr);*/
         If &bDisplayErrors Then
            /*error*/
            If &PSMessages.Item(&i).MessageType = 1 Then
               &errorText = &PSMessages.Item(&i).Text;
              /* MessageBox(0, "", &MsgSetNbr, &MsgNbr, "Message Not Found : " | &MsgSetNbr | "," | &MsgNbr);
               MessageBox(0, "", 0, 0, "&ExplainText = " | &ExplainText);
               MessageBox(0, "", 0, 0, "&Text = " | &Text); */

              /*InsertResults is a function that inserts &errorText for logging purposes*/
               InsertResults();
            End-If;
         End-If;
      End-For;
      &PSMessages.DeleteAll();
   End-If;
   
   Return &NbrErrors;
   
End-Function; /* CheckSessionMessages */

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Larry's picture
User offline. Last seen 2 years 31 weeks ago. Offline
Joined: 03/18/2008
Posts: 19
Re: PSMessages Collection - write to it...

Lepa,

Thanks, but it appears to me that your function is just looping thru the PSMessages Collection and calling the InsertResults() function once for each Message that has a Severity = Error, then Deleting all messages from the Collection once the loop is done.

What I need is something to help me populate the PSMessages Collection without calling the Error() or Warning() commands. I'm not seeing that, unless your InsertResults() routine does that. If so, then that is what I need to see. If not, then this really isn't what I need help with.

Regards,

Larry

Lepa's picture
User offline. Last seen 1 year 31 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: PSMessages Collection - how to write throwing

Hey Larry,
No, i'm not populating the PSMessages Collection. Infact, it gets populated on its own. PSMessages Collection is a property of the Session Class and i'm using the APIs that are accessible using a session object are:
• Component Interface Classes
• PortalRegistry Classes
• Query Classes
• Search Class
• Tree Classes

The session object handles error processing for the above APIs automatically, so no need to call the Error() or Warning() commands to log errors. In the code above, i'm running the error check after executing some Query class Peoplecode, and i call CheckSessionMessages( True); anytime I suspect an error might happen while using the Query methods and properties.

Are you using any of the above classes in your code?

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Larry's picture
User offline. Last seen 2 years 31 weeks ago. Offline
Joined: 03/18/2008
Posts: 19
Re: PSMessages Collection - how to write throwing

No. I was specifically looking for a way to populate the PSMessages Collection myself without calling Error() or Warning() to do so.

Guest's picture
Guest
PSMessage collection not populated with errors

Hi
I have created a custom CI..
When CI encounters any error it should be written into PSMESSAGES collection automatically.
But it is not happening..Can you help me out in this.
Thanks
Pazhanivel