
- 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-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-20-2023 05:56 AM
Thanks Amit, it works!