How to Display g_form.addErrorMessage() Permanently in ServiceNow.

zee15
Tera Contributor

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.

13 REPLIES 13

@zee15 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron

@zee15 

Would you mind closing your earlier questions by marking appropriate response as correct?

Members have invested their time and efforts in helping you.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Vaishnavi Lathk
Mega Sage

Hi @zee15 ,

 

You’re correct it g_form.addErrorMessage() is designed to be temporary and automatically disappears after a few seconds as part of ServiceNow’s out-of-box behavior. There isn’t a supported way to make this method permanently display on the form because it’s intended for short-lived validation or informational messages.

If you need a message to stay visible on the form, the better approach is to use alternatives that are designed for persistent messaging.

Recommended Approach

1. Use g_form.showFieldMsg() (most common solution)
This keeps the error message visible near a specific field until the user changes the value or refreshes the form.

function onLoad() {
    g_form.showFieldMsg(
        'short_description',
        'This error message will remain visible until the issue is resolved.',
        'error',
        false
    );
}

This is usually preferred because it clearly shows the user where the issue is and does not disappear automatically.

 

2. Use a UI Policy or Client Script to enforce validation

You can show a persistent message and also prevent submission:

function onSubmit() {
    if (g_form.getValue('short_description') == '') {
        g_form.addErrorMessage('Short description is mandatory.');
        return false;
    }
}

This ensures the message appears whenever the user tries to submit, even if it disappears later.

 

3. Use a Form Banner or Info/Error Section

For long-term warnings (like compliance or restrictions), many teams add:

  • Form banner
  • UI Macro
  • Portal/Workspace message
  • Read-only fields with explanation

This provides a permanent visual indicator without fighting the platform’s default behavior.

Best Practice

  • g_form.addErrorMessage() → temporary validation messages
  • g_form.showFieldMsg() → persistent field-level error
  • UI banner or policy → long-term or permanent message

Trying to override the auto-dismiss behavior of g_form.addErrorMessage() is not recommended, as it can lead to UI performance or usability issues.

 

Hope this helps!

 

Vishal Birajdar
Giga Sage

Hi @zee15 

You can use Annotation's on form designer.

 
 
 
 

annotation.png

 

anno2.png

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates