- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 07:38 PM
Hi all,
I have created an onChange catalog client script on a variable set on specific variable, and used:
g_form.showFieldMsg('variable_name', 'Test comment showed', 'error');
The msg shows under the field, however, it still allows the form to be submitted. Looking at the below KB this should not allow form to be submitted, any ideas if this is changed recently?
https://hi.service-now.com/kb_view.do?sysparm_article=KB0720733
Solved! Go to Solution.
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2019 12:03 AM
You will require to write on submit script as well. use below script for onchange
if(newValue == '0' || newValue == '1') {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot start with 0 or 1', "error");
}
var validate = new RegExp('^[0-9-_/:]+$');
var result = validate.test(newValue);
if(!result) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot have spaces or special characters other than - or /.', "error");
}
if(newValue.length < 6 && newValue.length !=0) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot be less than 6 digits', "error");
}
}
Use below code for the onSubmit
var newValue = 'Get value of variable';
if(newValue == '0' || newValue == '1') {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot start with 0 or 1', "error");
}
var validate = new RegExp('^[0-9-_/:]+$');
var result = validate.test(newValue);
var flag = true;
if(!result) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot have spaces or special characters other than - or /.', "error");
flag = false ;
}
if(newValue.length < 6 && newValue.length !=0) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot be less than 6 digits', "error");
flag = false;
}
if(flag == false)
return false ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2019 12:03 AM
You will require to write on submit script as well. use below script for onchange
if(newValue == '0' || newValue == '1') {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot start with 0 or 1', "error");
}
var validate = new RegExp('^[0-9-_/:]+$');
var result = validate.test(newValue);
if(!result) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot have spaces or special characters other than - or /.', "error");
}
if(newValue.length < 6 && newValue.length !=0) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot be less than 6 digits', "error");
}
}
Use below code for the onSubmit
var newValue = 'Get value of variable';
if(newValue == '0' || newValue == '1') {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot start with 0 or 1', "error");
}
var validate = new RegExp('^[0-9-_/:]+$');
var result = validate.test(newValue);
var flag = true;
if(!result) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot have spaces or special characters other than - or /.', "error");
flag = false ;
}
if(newValue.length < 6 && newValue.length !=0) {
g_form.showFieldMsg('VARIABLE_NAME', 'Cost cannot be less than 6 digits', "error");
flag = false;
}
if(flag == false)
return false ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2019 04:25 AM