OnSubmit client script condition if field value changes

Khalnayak
Tera Guru

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

so what's not working? where are you stuck?

regards
Ankur

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

not sure how to check if a certain variable has changed and if changed if it is same as another variable.

can you provide example please

Hi,

changed from what?

it's a new catalog form and if the value is empty on form load you can check with value != ''

it means value is given by user

Regards
Ankur

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

so not new form, existing HR case form view. not catalog form.

When value on opened for changes, and if the value for opened for is same as subject person, then there should be confirm popup.