flushMessages ServiceNow

Sumanth16
Kilo Patron

 

The flushMessages() method in ServiceNow is typically used in the context of the GlideSystem (referred to as gs) object. This method is used to clear any informational messages that have been queued up for display to the user during the execution of a script.

 

Usage

The flushMessages() method doesn't take any parameters, and its purpose is to ensure that all current messages are removed from the queue. This can be helpful if you want to clear messages before displaying new ones to the user.

 

Syntax

gs.flushMessages();
 

Example

Here's a simple example to demonstrate how you might use flushMessages() in a script:

gs.addInfoMessage("This is an informational message.");
gs.addErrorMessage("This is an error message.");
 
// Flush all messages
gs.flushMessages(); //
 
Now if you add another message, it will be the only message displayed
gs.addInfoMessage("New message after flushing previous ones.");
 

In this example:

  1. Two messages are added to the message queue.
  2. gs.flushMessages() clears all the messages that were added.
  3. The new message will be the only one displayed.

This method is helpful when you want to ensure that outdated or irrelevant messages are not shown to the user.

1 REPLY 1

Vikashv18
Tera Contributor

Hi @Sumanth16 ,

I have use case where all previous error messages must be removed and a certain message must be displayed. I believe the 'gs.flushMessages()' removes messages from the same script. Is there another function that will remove messages from all scripts triggers for a table.