- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 10:01 PM
Hi,
I'am using GlideRecord.get() to get single record and I have found this behavior strange happened during writing logic for my handler. If I put the an non-existence sys_id to the GlideRecord.get(), result of that function is an new object is created with the non-existence sys_id I put in ? And it get even worst when at the end of that process there is an GlideRecord.update(), the function automatically insert an new record to my desired table. Are these behaviors normal when using this function ? Also, is there any alternative function to get single record rather than using GlideRecord.get() ?
Below here are attachments of functions behaviors:
- Object is created with non-existence sys_id:
- An object is created when using gr.update():
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 10:11 PM
Hi @sieusaopolo15 ,
Always use an if condition whenever u want to fetch 1 record. U can try with below code.
var gr = new GlideRecord('u_testing_table_api');
if(gr.get('enter your sys Id here'){
gs.info('inside if');
}else{
gs.info('inside else');
}
Mark my answer helpful & accepted if it helps you resolve your query.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 10:11 PM
Hi @sieusaopolo15 ,
Always use an if condition whenever u want to fetch 1 record. U can try with below code.
var gr = new GlideRecord('u_testing_table_api');
if(gr.get('enter your sys Id here'){
gs.info('inside if');
}else{
gs.info('inside else');
}
Mark my answer helpful & accepted if it helps you resolve your query.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 10:16 PM
Hi @Danish Bhairag2, thanks for wonderful answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 10:28 PM
Hello @sieusaopolo15
.get() is used for returning a specific element among all the elements.
So when we used if statement for .next() function it checks the parameter into the filtered object i.e gr.
gr.next() will check the record in ,get() function.
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 02:51 AM
That is not quite correct. .get() will fetch more than one record, you then need to use .next() to iterate.
From the docs (https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_referenc...)
"If multiple records are found, use next() to access the additional records."
If this answer was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel