how to get sys_id from one table to another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2022 10:02 PM
Hello everyone,
I have table called 'XYZ' in that i have one reference field, what ever the am choosing the value from that reference field i need that sys_id. How to get it ? i tried below script its not working. I need a background script here.
Script:-
var gr = new GlideRecord('XYZ'); //main table
gr.addEncodedQuery('i put the some encoded query according to my need');
gr.query();
if(gr.next())
{
var grp = new GlideRecord('ABC'); //refernce field table
grp.name = gr;
var rp = grp.getValue('sys_id');
gs.print(rp);
}
Note: But sometimes the reference field will be empty. so at that time i need a sys_id of that particular record and update in the field. the sys_id will be vary for instnaces, so i can't hard core that value.
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2022 10:11 PM
Hi there,
If it's for example the sys_id of assigned_to in a task (extended) table (just an example!), then you could already use gr.assigned_to. No need to have a second GlideRecord query.
Using your code:
var gr = new GlideRecord('XYZ'); //main table
gr.addEncodedQuery('i put the some encoded query according to my need');
gr.query();
if(gr.next())
{
var rp = gr.field_you_are_after;
gs.print(rp);
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2022 10:50 PM
Its not an extended table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2022 11:09 PM
That doesn't matter.
Did you try what I mentioned? You are marking the answer from Abhijit as helpful, while that answer is exactly the same as what I mentioned earlier.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2022 11:22 PM
yeah its working fine. But sometimes the reference field will be empty. so at that time i need a sys_id of that particular record and update in the field. the sys_id will be vary for instnaces, so i can't hard core that value.