How to Display g_form.addErrorMessage() Permanently in ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
I have a requirement where an error message added using g_form.addErrorMessage() needs to be displayed permanently on the form.
Currently, I am adding the error message through a client script. The message appears initially, but after some time it automatically disappears. I understand that this is the out-of-box (OOB) behavior in ServiceNow.
Is there a way to override this behavior and make the error message persist on the form? If so, I would appreciate any guidance or best practices to achieve this.
Thanks in advance for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
You may use a UI Macro or form section instead
If the message is tied to a specific condition (like a field validation or record state), consider rendering a persistent visual element rather than relying on the transient notification system:
// Show/hide a dedicated field or HTML field on the form
g_form.setDisplay('u_error_banner', true);
g_form.setValue('u_error_banner',
'<div style="color:#c00;font-weight:bold;padding:8px;border:1px solid #c00;border-radius:4px;">' +
'Your persistent message here</div>');
create a macro/HTML variable or a dedicated field on the form specifically for this purpose. This is the cleanest approach for production use since you're not fighting the platform's OOB behavior.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @zee15
To make an error message persist permanently on a ServiceNow form, you can use g_form.showFieldMsg() instead of g_form.addErrorMessage()
g_form.showFieldMsg('<field_name>','Your message','error');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
49m ago
Hello @zee15 ,
Just to confirm the requirement — should the error message be displayed only when certain conditions are met (like based on field values), or is it meant to be a persistent alert/error message that appears on form load and never disappears regardless of user interaction?
