Hide Error Message on Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 02:15 PM
I have a self service catalog form which has many flows depending upon users "Yes" and "No" selection. For the last Yes/No selection, if user selects "No" and clicks "Add To Cart" then a Error message shows up "Sorry! You cannot complete this transaction" at the top of the screen. I want if this "No" condition is false i.e if user selects Yes or changes and any other previously selected Yes/No option then the Error Message should hide/go away. How can I achieve that?
Here is the Client Script:
function onSubmit() {
//Type appropriate comment here, and begin script below
var a1 = g_form.getValue('X');
if (a1== 'No'){
g_form.addErrorMessage('Sorry! You cannot complete this transaction.');
return false;
}
}
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 02:43 PM
You should be able to use g_form.clearMessages();
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideFormClearMessages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 03:27 PM
I did, still it did not work
function onSubmit() {
//Type appropriate comment here, and begin script below
var a1 = g_form.getValue('X');
if (a1== 'No'){
g_form.addErrorMessage('Sorry! You cannot complete this transaction.');
return false;
}
else{
g_form.clearMessages();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 04:32 PM
Hi
You can clear messages first every time onSubmit runs and show error message in answer in NO and return false.
function onSubmit() {
//Type appropriate comment here, and begin script below
g_form.clearMessages();
var a1 = g_form.getValue('X');
if (a1== 'No'){
g_form.addErrorMessage('Sorry! You cannot complete this transaction.');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 07:50 AM
It removed my predefined message box but not removing this error message box.