Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to compare reference field value in glide record

Renu9
Tera Contributor

Hi All,

 

On a field map script, I am comparing  a reference field value to a field value that is coming from the source feed. 

It is not getting compared even though the source value is available. Kindly help

var cmp= source.u_company;

grd = new GlideRecord('u_custom_table');
grd.addQuery('u_company_name', 'cmp'); 
grd.query();
if (grd.next()) {

//do something

}

else

{

//do something

}

 

Even though cmp is available in the custom table it is always going to else part.

Please guide me here. u_company_name is a reference field. How can I get the display value of u_company_name to compare with cmp

 

@Ankur Bawiskar  Kindly hhelp

 

1 ACCEPTED SOLUTION

@Renu9 

what I am saying is this

1) u_company_name refers to which table? in that which field holds the company name

Use that in the query as dot walked field

var cmp= source.u_company;

grd = new GlideRecord('u_custom_table');
grd.addQuery('u_company_name.u_name', cmp);  // don't give this in quotes

gs.log("display " +grd.u_company_name.name); // this will return undefined here as record not found yet
grd.query();
if (grd.next()) {

//do something

}

else

{

//do something

}

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Renu9 

source.u_company holds name and not sysId then query won't work

you need to dot walk to the field which holds the name present in the table being referred by u_company_name

Also small correction

var cmp= source.u_company;

grd = new GlideRecord('u_custom_table');
grd.addQuery('u_company_name', cmp);  // don't give this in quotes
grd.query();
if (grd.next()) {

//do something

}

else

{

//do something

}

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

Hi @Ankur Bawiskar  I am unable to get the display name of the reference field. Please guide with Sample script

 

var cmp= source.u_company;

grd = new GlideRecord('u_custom_table');
grd.addQuery('u_company_name.name', cmp);  // don't give this in quotes

gs.log("display " +grd.u_company_name.name); is returning undefined
grd.query();
if (grd.next()) {

//do something

}

else

{

//do something

}

@Renu9 

what I am saying is this

1) u_company_name refers to which table? in that which field holds the company name

Use that in the query as dot walked field

var cmp= source.u_company;

grd = new GlideRecord('u_custom_table');
grd.addQuery('u_company_name.u_name', cmp);  // don't give this in quotes

gs.log("display " +grd.u_company_name.name); // this will return undefined here as record not found yet
grd.query();
if (grd.next()) {

//do something

}

else

{

//do something

}

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