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.

Seeking Help with UI Page Client script

Still Learning
Kilo Sage

Hello Everyone, 

New developer here.  I have a requirement to add an alert message when a choice field selection is made and make work notes mandatory on the UI page.  The field is Validation Type (valtype on the UI page / 'validation_type' on the Form) when the user selects the option: "Accepting Risk/Not Testing" an alert popup message should appear and the work notes field should become mandatory. 

I've written a script in the client script section of the UI page but it is not working.  Can anyone please assist me with this?

 

Edited to remove code

 

1 ACCEPTED SOLUTION

SVimes
Kilo Sage

I took what you put together and started looking through what is actually rendered. There is an onchange event already attached to the <select> tag that is rendered on the page simply called onChange. It passes in the name of the ui_choice_input_field so it's easy to determine which input field changed in the function if you have more than one of them.

 

Using that, I changed the Client Script to the following which worked for the alert part:

function onChange(ui_choice_input_field_name){
	if(jQuery("#" + ui_choice_input_field_name + " option:selected").val() == "not_testing"){
		alert('By selecting Accepting Risk/Not Testing, you will be responsible for any issues with functionality experienced by your CI/Application post release activity. Please update the work notes with the reason you are accepting risk/not testing.');
		field.column_name = "work_notes_update";
		field.mandatory = true;
	}
}

 

I'm not sure about setting the field you want to Mandatory though since I don't know how the UI Page is accessed/rendered and there isn't a work_notes_update field on the UI Page with what you provided. I hope this gets you started at least.

Sable Vimes - CSA

View solution in original post

2 REPLIES 2

SVimes
Kilo Sage

I took what you put together and started looking through what is actually rendered. There is an onchange event already attached to the <select> tag that is rendered on the page simply called onChange. It passes in the name of the ui_choice_input_field so it's easy to determine which input field changed in the function if you have more than one of them.

 

Using that, I changed the Client Script to the following which worked for the alert part:

function onChange(ui_choice_input_field_name){
	if(jQuery("#" + ui_choice_input_field_name + " option:selected").val() == "not_testing"){
		alert('By selecting Accepting Risk/Not Testing, you will be responsible for any issues with functionality experienced by your CI/Application post release activity. Please update the work notes with the reason you are accepting risk/not testing.');
		field.column_name = "work_notes_update";
		field.mandatory = true;
	}
}

 

I'm not sure about setting the field you want to Mandatory though since I don't know how the UI Page is accessed/rendered and there isn't a work_notes_update field on the UI Page with what you provided. I hope this gets you started at least.

Sable Vimes - CSA

Thank you so much for your help with this script Claude!!! It worked exactly as I needed it to (and I learned what my mistakes were in the process) - thank you so much!!!