Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show message and prevent submission of form after selecting a specific value from choicelist

atxjb
Tera Contributor

Hello all, I have a choice list on a form in our Service Portal. After selecting a specific value in the choice list, I would like to have a message displayed that contains a URL link. Also, if the value is selected, I would like to prevent the user from being able to submit. Could you help out and let me know how this can be achieved? 

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage

Hi,

Create one onChange() Catalog Client Script on the required variable of your Catalog Item and utilize the below script.

UI Type: All

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below

    if(g_form.getValue('backend_name_of_choice_field>') == '<backend_value_of_choice>'){
		var url = 'https://www.google.com';
		g_form.addInfoMessage('<a href=' + url + ' target="_blank">Google</a>');
	}else{
		g_form.clearMessages();
	}

}

Then create onSubmit() Catalog Client Script on your required Catalog Item and utilize the below code.

UI Type: All

function onSubmit() {
	
	if(g_form.getValue('<backend_name_of_choice_variable>') == '<backend_value_of_choice>'){
		g_form.addErrorMessage('Cannot submit with this choice.');
		return false;
	}

}

View solution in original post

2 REPLIES 2

Yousaf
Giga Sage

Hi,

Please try onSubmit Client Script.

if(g_form.getValue('your field name'=='option you want')){
g_form.addInfoMessage('you cannot submit with this value selected.' <a href = '/incident_list.do'>Click</a>);
return false;
}

 

Mark Correct or Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Muhammad Khan
Mega Sage

Hi,

Create one onChange() Catalog Client Script on the required variable of your Catalog Item and utilize the below script.

UI Type: All

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below

    if(g_form.getValue('backend_name_of_choice_field>') == '<backend_value_of_choice>'){
		var url = 'https://www.google.com';
		g_form.addInfoMessage('<a href=' + url + ' target="_blank">Google</a>');
	}else{
		g_form.clearMessages();
	}

}

Then create onSubmit() Catalog Client Script on your required Catalog Item and utilize the below code.

UI Type: All

function onSubmit() {
	
	if(g_form.getValue('<backend_name_of_choice_variable>') == '<backend_value_of_choice>'){
		g_form.addErrorMessage('Cannot submit with this choice.');
		return false;
	}

}