GetMessageText

You can use the GetMessageText function to return the message text for a message code in the appropriate language.

The function determines the language by using the input parameter cultureName.

When to use

You must use this function to:

  • Display user-facing messages that have multiple languages.
  • Display localized error messages during error handling.

Syntax

int GetMessageText(string messageCode, ref string messageText, string cultureName = "")

Parameters

Parameter Type Required Description

messageCode

string Yes
The unique code identifier for the message.
Note: The unique ID must match a message code configured in the applications message repository.
messageText string (ref) Yes

The output parameter passed by reference. The parameter returns the localized message text associated with the specified message code.

Note: You must initialize this parameter as an empty string before calling the function.
cultureName string Optional

The language or culture code for displaying the message text. Possible values:

  • EN-US - English (United States)
  • EN-GB - English (United Kingdom)
  • JA-JP - Japanese (Japan)
  • ES-ES - Spanish (Spain)
  • FR-FR - French (France)
  • DE-DE - German (Germany)
  • IT-IT - Italian (Italy)
  • PT-BR - Portuguese (Brazil)
  • ZH-CN - Chinese (Simplified, China)
  • KO-KR - Korean (Korea)
Note: If this parameter is empty, the function retrieves the message text in the users default language.

Return Value

The application returns the parameter as an integer. Possible values:

  • 1 if the specified messageCode is found.
  • -1 if the specified messageCode is not found.

Prerequisites

  • The specified message code must be configured in the application by the administrators.
  • The specified culture code must be valid and supported by the application.

Examples

Example 1
Get Message text in Japanese and return the code as an integer.
public long wf_start()
{
    string msgJapanese = "";
    int rtn = GetMessageText("ITEMNOTFOUND", ref msgJapanese, "JA-JP");

    // Log the integer return code
    MessageList("return for JA-JP: ", rtn);

    // Also log the localized message text (if found)
    if (rtn == 1 && !string.IsNullOrEmpty(msgJapanese))
        MessageList("Message text (JA-JP): ", msgJapanese);
    else
        MessageList("Message text not found for code ITEMNOTFOUND in JA-JP.");

    return 1L;
}
Example 2
Retrieve and display message text in the default language.
public long wf_start()
{
    string msg = "";
    int rtn = GetMessageText("FORMULACALCFAILED", ref msg);

    if (rtn == 1 && !string.IsNullOrEmpty(msg))
        MessageList("Msg: " + msg);
    else
        MessageList("Msg: <not found>");

    return 1L;
}
Example 3
Retrieve and display message text in French.
public long wf_start()
{
    string msg = "";
    int rtn = GetMessageText("FORMULACALCFAILED", ref msg, "FR-FR");

    if (rtn == 1 && !string.IsNullOrEmpty(msg))
        MessageList("Msg: " + msg);
    else
        MessageList("Msg: <not found>");

    return 1L;
}
Example 4
Retrieve and display message text in the browsers default language.
public long wf_start()
{
    // Get current session language
    string sLanguage = Context.SessionInfo.Language;

    // Initialize output string for GetMessageText
    string msg = "";

    // Call GetMessageText (returns 1 if found, -1 if not)
    int rtn = GetMessageText("FORMULACALCFAILED", ref msg, sLanguage);

    // Log the integer return code and localized message text
    MessageList("GetMessageText rtn: " + rtn.ToString());
    MessageList("Lang: " + sLanguage + " | Msg: " + (string.IsNullOrEmpty(msg) ? "<not found>" : msg));

    return 1L;
}