How to clear Messages on a Business Rule

Meloper
Kilo Sage

i tried:

gs.clearOutputMessages();

and

gs.clearMessages();

but it does not work

1 ACCEPTED SOLUTION

BALAJI40
Mega Sage

Hi,

Clear/hide messages will work only on the client side.

or you can try with the flush message on the server-side.

find_real_file.png

 

View solution in original post

14 REPLIES 14

Vaishnavi Lathk
Mega Sage
Mega Sage

Hi,

Business rules are executed synchronously on the server (unless async is used).
The API gs.addErrorMessage() queues a message to be displayed to the end user in their web browser/device.
Alas, adding a 5 seconds sleep will do nothing but add 5 seconds to the Business Rule execution time.

You need to add an onLoad Client Script to do this after your Business Rule returns.
You will need your condition to mimic the Business Rule conditions, otherwise, all messages will be cleared after 5 seconds.

For example, if your Business rule condition is 'State' is "In Progress" in the Incident [incident] table, your onLoad Client Script for Incident would have this code:

if (g_form.getValue('state') == 2) { // IN PROGRESS
setTimeout(g_form.clearMessages, 5000); // 5 SECONDS
}

https://www.w3schools.com/jsref/met_win_settimeout.asp

 

Regards,

Vaishnavi Lathkar

BALAJI40
Mega Sage

Hi,

Clear/hide messages will work only on the client side.

or you can try with the flush message on the server-side.

find_real_file.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Meloper 

those messages are generated from BR or some client side script?

Regards
Ankur

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

BR too, sometimes this BR i running 3-4 Times at the same time, and i want to prevent the 4 Messages appears for the User.

to describe with more details:

it is a ServerSide ui Action.

if you select 5 Approvals (checkbox on the Leftside) an Select a List Action. The Action runs for every selected Record.

So only after the last Check the Message should stay on the form.