Client Script onChange - getReference()

Halo10110
Giga Contributor

Hello, 

I have to compare two reference values from two different tables in onChange client script and am stuck, it works for one, but not sure how to implement the logic to actually compare the values...Any suggestion what is wrong with my script? Please do not tell me that this can be achieved with GlideAjax, I know that but chose this way as it seems easier and more reliable for my case. 

function onChange(control, oldValue, newValue, isLoading) {
	g_form.getReference('u_one_field', validation); 
	g_form.getReference('u_second_field', validation);
}

function validation(demo, show) { // reference is passed into callback as first arguments
	if(demo.active === 'true' && show.u_rule === '2'){
		g_form.showFieldMsg('u_one_field','TEST','info');
	}
}

 

1 ACCEPTED SOLUTION

Thanks it might work, however I fixed it like this (without the callback function)

 

	var demo = g_form.getReference('u_one_field').active;
	var show = g_form.getReference('u_second_field').u_rule;
	if(demo === 'true' && show === '2'){
		g_form.showFieldMsg('u_one_field','TEST','info');
	}

 

Thanks for posting actual helpful answers.

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Better approach would be to send both the values to script include using GlideAjax, query required table, get the field values and compare there and return the result.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Terrible and very inacurate answer to my question, "Please do not tell me that this can be achieved with GlideAjax, I know that but chose this way as it seems easier and more reliable for my case." please elaborate better 🙂

Harsh Vardhan
Giga Patron

can you try now. 

i can only see the difference here, you did not declare the variable. 

 

Updated Script:

 

function onChange(control, oldValue, newValue, isLoading) {
	var demo= g_form.getReference('u_one_field', validation); 
	var show =g_form.getReference('u_second_field', validation);
}

function validation(demo, show) { // reference is passed into callback as first arguments
	if(demo.active === 'true' && show.u_rule === '2'){
		g_form.showFieldMsg('u_one_field','TEST','info');
	}
}

Thanks it might work, however I fixed it like this (without the callback function)

 

	var demo = g_form.getReference('u_one_field').active;
	var show = g_form.getReference('u_second_field').u_rule;
	if(demo === 'true' && show === '2'){
		g_form.showFieldMsg('u_one_field','TEST','info');
	}

 

Thanks for posting actual helpful answers.