- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 04:55 AM - edited 11-29-2022 05:02 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:46 AM
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
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 05:09 AM
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
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 06:10 AM - edited 11-29-2022 06:14 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 07:46 AM
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
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader