
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 07:49 AM
Hi,
I have 2 client scripts on the same field, each one will display specific message based on the selection. I need to clear the message if selection changed. But when I change the option the old message still there (see screenshot).
This field has 5 options 2 of them should display a message
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:46 AM
HI @sparkles ,
I trust you are doing great.
It seems like the issue you're encountering is due to the persistence of the info message when the selection changes. In ServiceNow, when you use g_form.addInfoMessage()
, it adds a message to the form but does not automatically clear previous messages when the field value changes.
First script:
var _link = '<a href ="https://testlink.com/sites/xxxx" target="_blank">Form.</a>';
// Clear existing messages before adding a new one
g_form.clearMessages();
// Add the form message for the 'first' option
if (newValue == 'first') {
g_form.addInfoMessage('Please download, complete and attach "XXX ' + _link);
}
Second Script
var _link = '<a href ="https://testlink.com/sites/xxxx" target="_blank">Form.</a>';
// Clear existing messages before adding a new one
g_form.clearMessages();
// Add the form message for the 'second' option
if (newValue == 'second') {
g_form.addInfoMessage('Please download, complete and attach "XXX ' + _link);
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 08:00 AM
Hi @sparkles,
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 08:11 AM
Hi Sagar,
Thanks for your reply, that made the message for the second option no longer shows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 09:10 PM
Hi @sparkles,
Apologies for the confusion. Rather than creating two separate client scripts for the same field/variable, you can consolidate them into a single client script, which will fulfill your requirements.
If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:18 AM