How to clear a specific message at the top of the form

jmweli
Kilo Expert

Hi ServiceNow Community Developers,

 

Is there a way to clear a specific message at the top of the form? Right now I am using gs.clearMessages() however the problem with this API is that clears all messages at the top of the form even the ones I don't want to clear at that point.

 

Here is an example: I have a message that gets displayed at the top of the form by an onLoad client script, then I have a boolean (true / false ) field that displays a message at the top of the form depending on its value. If checked it displays the message, if unchecked it clears the message. I am doing all this in this boolean field by means of a onChange client script. The problem is when I uncheck this boolean field it then clears all the messages at the top of the form even the one that was put there by an onLoad client scripts. Is there a way I can overcome this issue? Please advise.

 

Thanks,

Johannes

1 ACCEPTED SOLUTION

jmweli
Kilo Expert

Hi Subhajit,



Thanks for your suggestion. I managed to get this to work. Basically what I did was on the onchange client script where the gs.clearMessages() was clearing all messages out I went to the messages that were unintentionally getting cleared and checked how they were set up in the first place. I then included in my onchange client script the same condition that was setting them up and I got the desired behavior. So basically I set them back after unintentionally clearing them. In the end this was way easier than I thought.



Johannes


View solution in original post

6 REPLIES 6

HarshTimes
Tera Guru

Hi Guys

I understand that this is a very old message string. I was in smilar situation where I was required to clear a specific message. I tuned my client script the best i can do but still i was missing the functionality of clearing a specific message.

Unfortunately, there is no solution for this. So i raised a enhancement request for this FTASK40851. My request details are below

Title - Clear specific InfoMessage or ErrorMessage

Description

ClearMessages() in client script clear all the message on the form. There should be some functionality to clear a specific message instead of clearing all the message.
Suggesstion:
Info Message or ErrorMessage should have a unique ID that can be used in clearMessages() function as a parameter to clear only that specific message instead of clearing all info/error message.

 

I request you guys to raise a similar enhancement request so that this feature gets the priority and servicenow development team can comeup with some solution for this soon.

 

 

Regards,

Harsh

 

Hey Harsh,

 

Have you had any luck with the request you submitted and found any alternative to the clear message? even I stuck with similar issue.

 

Thanks