Success and Error Message property
Less than to read
In the JSON schema, “success_message” and “error_message” are valuable tools for communicating with end users. “success_message” informs users about a successful process, while “error_message” provides information about failed processes.
When to Use Success and Error Messages
-
Success Messages: Use “success_message” when you want to provide positive feedback to users after a successful process. It can improve the user experience by confirming actions.
-
Error Messages: Use “error_message” when you need to inform users about issues, errors, or exceptions during a process. Including a title and detailed message can help users understand and resolve the problem.
Success Message
“success_message” is used to notify users when a process has completed successfully. It takes a simple string message that provides feedback to the user. This could when when a screen is saved or when a user interactives with your customiation.
Example: Adding a Success Message
Here’s an example of how to use “success_message” to notify users of a successful department update:
{
"tryCatch": {
"try": [
{
"apiPutCollection": {
"endpoint": "v1/departments",
"prefix": "tab2Prefix",
"key": "departments"
}
},
{
"set": {
"success_message": "Department updated successfully"
}
}
],
// ...
}
}
In this example, after successfully updating the department data, a “Department updated successfully” message will be displayed to the user.
Error Message
“error_message” is used to communicate errors or issues that occur during a process. It can provide more detailed information than “success_message” and can include a title for the error message.
- The
title
` property represents the title of the error message, providing a brief summary of the encountered error. - The
message
` property contains the detailed description or explanation of the error, including any instructions or suggestions for resolution.
Example: Adding an Error Message
Here’s how to use “error_message” to notify users with just a message:
{
"tryCatch": {
"try": [
// ...
],
"catch": [
{
"set": {
"error_message": {
"message": "Department update failed"
}
}
}
]
}
}
In this example, if the catch block is triggered, the user will see an error message with the message “Department update failed.”
Example: Adding an Error Message with a Title
To provide a more structured error message, you can include a title:
{
"tryCatch": {
"try": [
// ...
],
"catch": [
{
"set": {
"error_message": {
"title": "Error Updating Department",
"message": "Department update failed"
}
}
}
]
}
}
In this example, an error message with the title “Error Updating Department” and the message “Department update failed” will be shown to the user in case of an error.
Using “CURRENT_ERROR”
The “CURRENT_ERROR” state allows you to display specific error details from your application. It’s especially useful when handling errors from API requests.
Here’s how to set the message to the value of “CURRENT_ERROR”:
{
"tryCatch": {
"try": [
// ...
],
"catch": [
{
"set": {
"error_message": {
"title": "Error Updating Department",
"message": {
"get": {
"state": "CURRENT_ERROR"
}
}
}
}
}
]
}
}
In this example, the error message will include the title “Error Updating Department” and the specific error message retrieved from the “CURRENT_ERROR” state.
For instance, if you attempted to edit the Department Code, you would receive an error message stating ‘The department code cannot be amended,’ as shown below:
Error Message using CURRENT_ERROR