- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:54 AM
Hi all,
For example, A and B are reference fields of incident. I want to compare A.a and B.b in client script, how can I do that?
I know g_form.getReference() but looks like only one reference field can be fetched.
Regerds,
Eric
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 01:06 AM
Hi,
Assuming you want to compare some other fields based on the reference field of A and B, you can do liek this.
var a = g_form.getReference("A"); //put correct field names
var b = g_form.getReference("B"); //put correct field names
if(a.your_field == b.your_field) {
//do something.
}
Mark the comment as a correct answer if it solves your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 01:02 AM
Hi,
Assuming you want to compare if same users are selected in both the fields
you can use this logic
var a = g_form.getValue('field A');
var b = g_form.getValue('field B');
if(a==b){
alert('both users are same');
}
Regards
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
07-14-2020 01:06 AM
Hi,
Assuming you want to compare some other fields based on the reference field of A and B, you can do liek this.
var a = g_form.getReference("A"); //put correct field names
var b = g_form.getReference("B"); //put correct field names
if(a.your_field == b.your_field) {
//do something.
}
Mark the comment as a correct answer if it solves your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 03:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 01:08 AM
Hi Phonexi,
Its working fine for me If you use g_form.getReference in two fields :
client scritp:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var a = g_form.getReference('caller_id');
var b = a.email;
var c = g_form.getReference('assigned_to')
var d = c.name;
alert('caller email '+b + ' Assigned to name '+ d);
//if(a.email == c.email) use any condition
//Type appropriate comment here, and begin script below
}
OUtput:
You can compare with both the values:
Mark helpful and correct if it helps.
Thansk,
CB