- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 06:13 AM
Hi, I'm stuck figuring out how to compare two values to result in a Yes or No in the 3rd variable.
so far,my script looks like this:
Please help.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 06:16 AM
Hi,
Can you change it as below and see if it works?
var frompcowner = g_form.getValue('from_pc_owner');
var remotepcowner = g_form.getValue('remote_pc_owner');
if(frompcowner == remotepcowner ){
//Set to Yes
}else{
//Set to No
}
You dont need to do a getReference for getting the sys_id. The id is directly stored as value in reference fields.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 06:16 AM
Hi,
Can you change it as below and see if it works?
var frompcowner = g_form.getValue('from_pc_owner');
var remotepcowner = g_form.getValue('remote_pc_owner');
if(frompcowner == remotepcowner ){
//Set to Yes
}else{
//Set to No
}
You dont need to do a getReference for getting the sys_id. The id is directly stored as value in reference fields.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 06:18 AM
I would go with Alikutty's solution of using getValue instead of getReference. getValue will give you the sys_id of the record in the variable whereas getReference actually does a server roundtrip and grabs the referenced record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 06:40 AM
Thank you, it worked! I thought that since the variables are Reference type, I have to use getReference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2019 06:21 AM
Hi,
if those are reference fields then no need to use getReference(); update code as below
if(g_form.getValue('from_pc_owner') == g_form.getValue('remote_pc_owner')){
}
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