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

Hi @Khalnayak 

Apologies if the below is stating the obvious, but in case not...

1) I notice the script above only checks to see if the Opened_For changed. What happens if the Subject_Person changes, do you not also need to check for that? Or is this field locked once the Case is raised?

2) Additionally it might also be worth considering creating OnCellEdit scripts if the fields you're comparing can be changed in the list view.

3) Finally, obviously I no have idea about the HR rules of your company, but your requirement seems to imply that if the person in the Subject_Person field is not the same as the person in the Opened_For field they should not see the Case.

If my understanding is correct, you might need to consider what to do in the scenario where the user in the Subject_Person has a role that grants them access to HR Cases (i.e. they work in HR) and thus CAN see it even when you might not want them to.

Best,

Mark

Hi Ankur, the property 'changed' is not working for me.

NikhilGupta_0-1680366875548.png

 

NikhilGupta_1-1680366939912.png

 

Hi @Nikhil Gupta . May I know what solution did you use as I am also facing the same...

 

Thank you