showFieldMsg with error still allows to submit form

Sam198
Mega Guru

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

 

1 ACCEPTED SOLUTION

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 ;
	
}

View solution in original post

6 REPLIES 6

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 ;
	
}

Hi, Thanks for assist with script, only problem with above script is that it does not allow to submit form when the number is entered correct - it still gives alert message.