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.

OnSubmit client script condition if field value changes

Khalnayak
Kilo Sage

HI,

I have a onsumit client script on a form, when a value of a field changes I need to check if the value is same as another field and if so, do a confirm popup.

Can someone help with this please.

1 ACCEPTED SOLUTION

Hi,

update as this

function onSubmit() {

	var subjectPersonValue = g_form.getValue('subject_person');
	var openedForValue = g_form.getValue('opened_for');
	var openedFor = g_form.getControl('opened_for');
	
	if(openedFor.changed){
		if (subjectPersonValue == openedForValue) {
			confirm("You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?");
		}
	}
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Hi,

you can use this to check if field got changed

function onSubmit(){

	if(g_form.isUserModified('field_name')){
		// check for value and show alert
	}

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi, I used that but getting error

find_real_file.png

 

function onSubmit() {
 
	var subjectPerson = g_form.getValue('subject_person');
	var openedFor = g_form.getValue('opened_for');
	

		if(g_form.isUserModified('opened_for')){
		if (subjectPerson == openedFor) {
			confirm("You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?");
			
	
}
}
	}

Hi,

is the field name correct?

is the field opened_for present on the form?

g_form.isUserModified('field_name') should work on normal form view

possibly g_form.isUserModified('field_name') is not supported in portal

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

hi @Ankur Bawiskar yes field name is correct and visible on the form.

I am not using portal.

Hi,

update as this

function onSubmit() {

	var subjectPersonValue = g_form.getValue('subject_person');
	var openedForValue = g_form.getValue('opened_for');
	var openedFor = g_form.getControl('opened_for');
	
	if(openedFor.changed){
		if (subjectPersonValue == openedForValue) {
			confirm("You have set the Opened For to the Subject Person, which will grant them access to view the Case - are you sure?");
		}
	}
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader