- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 03:42 AM
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');
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 05:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 03:53 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 04:26 AM
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 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 05:04 AM
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');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 05:20 AM
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.