- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:39 PM
The following code is coming back undefined when I try to call it.
var item = new GlideRecord('sc_req_item');
item.addQuery('request',current.sys_id);
item.query();
gs.addErrorMessage(item.number);
The request field is a reference to the parent of the req item. Iv'e tried both current.sys_id and current.getUniqueValue().
Im just trying to grab the child record from the request. The code seems right to me am I missing something? Thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:56 PM
A couple things... you need to actually DO something with the gliderecord. Also, name your variable a little differently, because the sc_req_item table already has a property called "item" on it, so don't want collisions there.
var gritem = new GlideRecord('sc_req_item');
gritem.addQuery('request',current.sys_id);
gritem.query();
while (gritem.next()){
gs.addErrorMessage(gritem.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:52 PM
Hi Michael,
Please add item.next() and print the value.
Refer to the updated code below:
var item = new GlideRecord('sc_req_item');
item.addQuery('request',current.sys_id);
item.query();
if(item.next()){
gs.addErrorMessage(item.number);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:55 PM
Hi,
You'd need to "step" into the actual record the query found by using appropriate format.
I'd recommend checking out the GlideRecord API documentation as you're very close 🙂 -- just need another step.
You'd use
if (item.next()) {
//do x
}
For one record
or
while (item.next()) {
//do x
}
To repeat an action x number of times depending on how many records have been found.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 06:18 AM
Hi Michael,
I'm glad you found the correct answer that worked for you.
I hope the other replies above were also helpful (pretty sure we all said the same thing?).
I also included documentation to the GlideRecord API as well, did that help or would help you?
Thanks and take care! 🙂
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 12:56 PM
A couple things... you need to actually DO something with the gliderecord. Also, name your variable a little differently, because the sc_req_item table already has a property called "item" on it, so don't want collisions there.
var gritem = new GlideRecord('sc_req_item');
gritem.addQuery('request',current.sys_id);
gritem.query();
while (gritem.next()){
gs.addErrorMessage(gritem.number);
}