Question
· 21 hr ago

How can I view the contents of the request object being sent in my BPL in Message Viewer Body?

I am looking to view the contents of the request object I am sending from my Service into my BPL in Message Viewer. My request contains references to other defined classes.

Class bd.webapp.OutboundMessageRequest Extends (%Persistent, Ens.Request)
{

Property Metadata As bd.webapp.OutboundMessageRequestMetadata;
Property MessageContent As %DynamicObject;
}



Class bd.webapp.OutboundMessageRequestMetadata Extends (%RegisteredObject, %JSON.Adaptor)
{

Property RegionSlug As %String;
Property TenantSlug As %String;
Property SystemSlug As %String;
Property MessageId As %String;
Property MessageType As %String [ InitialExpression = "JSON" ];
Property OccurredAt As %String;
Property CorrelationId As %String;
}

How can I view the contents of a property that is a custom class object in my Message Viewer Body?

I have tried to edit the %ShowContents method but have not been able to successfully showcase the "Metadata" property.

Method %ShowContents(pZenOutput As %Boolean = 0)
{
    If $ISOBJECT(..MessageContent) {
        Set json = ..MessageContent.%ToJSON()
        set formatter = ##class(%JSON.Formatter).%New()
        If pZenOutput {
            Write formatter.Format(json)
        } Else {
            Write json
        }
    } 

What I see on the Message Viewer:

Contents show the value of "MessageContent", but the value of "Metadata" is missing:

Product version: IRIS 2025.2
Discussion (1)2
Log in or sign up to continue

You need to edit the %ShowContents method in your class to properly display custom objects like the Metadata property in the Message Viewer. The issue is related to how the data is being exported.

You can achieve your goal by ensuring your class and its referenced objects (such as bd.webapp.OutboundMessageRequestMetadata) extend %JSON.Adaptor. This way, you can easily display their contents as JSON in the Message Viewer. Here's an example of how this can be done:

  1. Make the classes JSON-adaptable:
    Update your class definitions so that they extend %JSON.Adaptor. For instance:

    Class bd.webapp.OutboundMessageRequest Extends (%Persistent, Ens.Request, %JSON.Adaptor)
    {
       Property Metadata As bd.webapp.OutboundMessageRequestMetadata;
       Property MessageContent As %DynamicObject;
    }
    
    Class bd.webapp.OutboundMessageRequestMetadata Extends (%RegisteredObject, %JSON.Adaptor)
    {
       Property RegionSlug As %String;
       Property TenantSlug As %String;
       Property SystemSlug As %String;
       Property MessageId As %String;
       Property MessageType As %String [ InitialExpression = "JSON" ];
       Property OccurredAt As %String;
       Property CorrelationId As %String;
    }
    
  2. Customize the %ShowContents Method:
    Override %ShowContents to format and display the data in JSON format. For example:

    Method %ShowContents(pZenOutput As %Boolean = 0)
    {
       set jsonExport = ""
       do ..%JSONExportToString(.jsonExport)
       set formatter = ##class(%JSON.Formatter).%New()
       do formatter.FormatToString(jsonExport, .formattedJson)
       if pZenOutput {
           &html<<pre>#(formattedJson)#</pre>>
       } else {
           write formattedJson
       }
    }
    

This setup will allow the Message Viewer to display properly formatted JSON containing the Metadata property, along with any other nested or dynamic properties defined within your class structure [1][2].

Sources: