The CreatorCon Call for Content is officially open! Get started here.

Catalog Client Script for comparing two values

alberttagle
Tera Contributor

Hi, I'm stuck figuring out how to compare two values to result in a Yes or No in the 3rd variable.

find_real_file.png

so far,my script looks like this:

find_real_file.png

Please help.

 

Thanks!

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

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!

View solution in original post

4 REPLIES 4

Alikutty A
Tera Sage

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!

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.

Thank you, it worked! I thought that since the variables are Reference type, I have to use getReference.

 

Ankur Bawiskar
Tera Patron
Tera Patron

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

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