Skip to main content

getCustomMessage

This function retrieves a custom message from the brixxbox message manager. It supports parameter substitution in the message text and allows you to specify the target language for internationalization.

Syntax

app.getCustomMessage(messageName, parameters, language)

Parameters

ParameterTypeDescription
messageNameStringThe unique name of the message to retrieve
parametersObject(Optional) An object containing key-value pairs for parameter substitution in the message
languageString(Optional) The language code to retrieve the message in (e.g., "en-US", "de-DE"). If not specified, uses the current user's language

Return Value

Returns a String containing the message text with any parameters substituted.

How Parameter Substitution Works

Parameters in messages are denoted by placeholders in curly braces, such as {param1} and {param2}. When you pass an object with matching keys, the function replaces these placeholders with the corresponding values.

Examples

Example 1: Basic usage with parameter substitution:

// Get a welcome message with the user's name
const welcomeMessage = app.getCustomMessage(
"welcomeMessage",
{ "userName": app.getFieldValue("fullName") }
);

// Display the message
app.showMessage("Welcome", welcomeMessage);

Example 2: Retrieving a message in a specific language:

// Get an error message in US English
const errorMsg = app.getCustomMessage(
"validationError",
{ "fieldName": "Invoice Number", "errorType": "duplicate" },
"en-US"
);

// Set the error message in a field
app.setFieldValue("errorMessageDisplay", errorMsg);

Example 3: Complex parameter substitution for a notification:

// Get a shipment notification with multiple parameters
const notification = app.getCustomMessage(
"shipmentNotification",
{
"orderNumber": app.getFieldValue("orderNumber"),
"expectedDate": app.getDate(app.getFieldValue("deliveryDate"), "short"),
"itemCount": app.getFieldValue("itemCount")
}
);

// Send the notification
app.sendEmail({
to: app.getFieldValue("customerEmail"),
subject: "Your Order Has Shipped",
body: notification
});
  • showMessage() - For displaying a message in a dialog box
  • showInfoMessage() - For displaying an informational message
  • showErrorMessage() - For displaying an error message
  • getDate() - For formatting dates that may be included in custom messages
  • setFieldValue() - For setting field values with retrieved messages

Notes

  • Messages must be defined in the message manager before they can be retrieved
  • If a message with the specified name is not found, the function returns the message name
  • Parameter names are case-sensitive
  • This function is particularly useful for:
    • Creating multi-language applications
    • Centralizing text management
    • Standardizing messages across your application
    • Dynamic message generation with context-specific information