Accessing Messages from the SmartFramework Message table

The SmartFramework message table (SmartDB.SmartMessage) contains messages by:

 

  • MessageGroup
  • MessageNumber
  • Language
  • MessageText
  • MessageDetail 
  • MessageType

 

There are two ways to retrieve messages from the SmartFramework message table (for instance in Business Entity Validation), localized to the language of the current user – or the default language when the message is not translated to the current user.

Using the MessageFormatter class


The MessageFormatter classwill return an error message token that includes the message group, the message number and the 0 to 9 parameters (ABL SUBSTITUTE function limits).

You can pass something like

Consultingwerk.SmartFramework.MessageFormatter:GetMessage ("DMS", 47, "Stock") 

to a Validate method call. And the message text will be returned like this: “SmartMessage~tDMS~t47~Stock”

The SmartComponent Library frontend translates this into “Product is out of Stock (DMS 47)” by retrieving (and caching) the message text from the message table.

Using the IMessageProvider service

 

Developers can call into the IMessageProvider service:

DEFINE VARIABLE oMessageProvider AS Consultingwerk.SmartFramework.IMessageProvider NO-UNDO .
DEFINE VARIABLE cMessage         AS CHARACTER                                      NO-UNDO .

oMessageProvider = {Consultingwerk/get-service.i Consultingwerk.SmartFramework.IMessageProvider} .
       
IF VALID-OBJECT (oMessageProvider) THEN
    cMessage = oMessageProvider:GetMessageText ("DMS":U, 47, "Stock") .       

or shorter:

cMessage = {Consultingwerk/get-service.i Consultingwerk.SmartFramework.IMessageProvider}:GetMessageText ("DMS":U, 47, "Stock") .        

or even shorter (requires at least OpenEdge 11.4):

USING Consultingwerk.SmartFramework.* .    /* get-service.i does only support USING on OpenEdge 11.4 */
 
/* .... */

cMessage = {Consultingwerk/get-service.i IMessageProvider}:GetMessageText ("DMS":U, 47, "Stock") .        

 

The backend would retrieve the message text from the message table. So the resulting string in the ProDataset Buffer ERROR-STRING attribute would be: “Product is out of Stock (DMS 47).” – in the language of the current user.

The first option provides the benefit of less date in the ProDataset buffer ERROR-STRING attribute and the consumer (GUI client, etc.) can decide at message display time in which language the message should be shown. This would also allow to log the message to a logfile in a different language (that would be understood by developers or tech-support staff).The SmartComponent Library GUI for .NET framework will be able to cache messages in the appropriate language (or the default language when no translation is there).

However, this requires the ability to call into the message provider when showing (or logging) the human readable message text. This may be difficult on a mobile or html based client. In these cases, option 2 has already returned the human readable message text and it’s just easier to handle in custom code.

In option 1, the ServiceInterface code (or other code that needs to translate the message into the human readable form) will need to call into the Consultingwerk.Util.ErrorHelper class to perform this translation and substitution.

So generally, option two is the easiest to use.