Why do we need getMessage in below Script

Sachin G K1
Kilo Sage

Hi All,

I was going through one OOB Ui Action Script and noticed that they have getMessage as you can see in below picture. Why do we need getMessage here, why not just g_form.addErrorMessage().

SachinGK1_0-1704992667545.png

 

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Sachin G K1 

 

As @Sandeep Rajput mentioned, if the key doesn't exist in the sys_ui_message table, then the key (first parameter in the getMessage() method) is displayed. If you want to add localization and translations to this value, then you can create this message and additional messages for each language as required and never have to update the script.

 

So circling back to your original question: 'Why do we need getMessage in below Script'

Answer: The getMessage method is simply used for localization and translation. When a client script contains a getMessage call or a server script contains a gs.getMessage call, the system checks the Message [sys_ui_message] table for translated text. If the Message [sys_ui_message] does not contain a matching value based on the 'key', the message displayed is as per the original script, and first parameter. In your case, Cannot propose major incident as 'Worknotes' is not visible.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

Basically, if and when you add various language support to your instance, you don't need to change or maintain the code. 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

17 REPLIES 17

Hi,

SachinGK1_0-1704994155181.png

I couldn't find the key

@Sachin G K1,

 

Remove the single quotes at the start and end of the String. Simply search using:

Cannot propose major incident as 'Worknotes' is not visible

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

 

SachinGK1_0-1704994599291.png

Not showing

Iraj Shaikh
Mega Sage
Mega Sage

Hi @Sachin G K1 

 

The `getMessage` is used to retrieve messages from the system's message table (sys_ui_message). This allows for the localization and internationalization of messages, meaning that the message can be translated into different languages based on the user's preferences or system settings.

The reason `getMessage` is used instead of directly calling `g_form.addErrorMessage("Your error message here")` is to support this localization. If you hard-code the error message string, it will always be in the language you wrote it in, which is not ideal in a multi-language environment.


Here's a breakdown of the code you provided:

1. It checks if the 'work_notes' field is visible on the form.
2. If it is not visible, it uses `getMessage` to retrieve a localized message that says "Cannot propose major incident as 'Worknotes' is not visible".
3. Once the message is retrieved, it is passed as an argument to the callback function, which then uses `g_form.addErrorMessage` to display it as an error message on the form.
4. The function returns `false` to prevent further action (such as submitting the form or executing additional code).

By using `getMessage`, the system can display the error message in the user's preferred language, if a translation is available in the message table. This is a best practice for creating applications that can be used globally.

Please mark this response as correct or helpful if it assisted you with your question.

Hi, Is "Cannot propose major incident as 'Worknotes' is not visible" is a key?