- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 03:49 AM
If I try to return a single record using GlideQuery.getBy
var tps = '9ae4fc341b835e500d6b2131b24bcbed', examiner = '6b50e0560a0aa007000e4447ebea7f12';
var result = new global.GlideQuery('x_uob15_tps_examiner_nomination').getBy({
parent: tps, internal_examiner: examiner, category: 'internal'
}, ['number', 'parent$DISPLAY', 'internal_examiner$DISPLAY']);
gs.warn(JSON.stringify(result));
I get this result
{"_value":null,"_lazyValueFetched":false}
If I use GlideQuery.where
var tps = '9ae4fc341b835e500d6b2131b24bcbed', examiner = '6b50e0560a0aa007000e4447ebea7f12';
var result = new global.GlideQuery('x_uob15_tps_examiner_nomination')
.where('parent', tps).where('internal_examiner', examiner).where('category', 'internal')
.select('number', 'parent$DISPLAY', 'internal_examiner$DISPLAY')
.toArray(100);
gs.warn(JSON.stringify(result));
The result is an array with 1 record
[{"number":"TPEX0011209","parent$DISPLAY":"TPS0004464","internal_examiner$DISPLAY":"XXXXXXXXXXX","sys_id":"b63c6e171b6b92503e49dd31b24bcbff"}]
Why is the GlideQuery.getBy method not working as expected?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 04:08 AM
Hi @Colleen
Include .orElse in your script. As per porduct doc, getBy method returns an optional object and it must include .orElse
var tps = '9ae4fc341b835e500d6b2131b24bcbed', examiner = '6b50e0560a0aa007000e4447ebea7f12';
var result = new global.GlideQuery('x_uob15_tps_examiner_nomination').getBy({
parent: tps, internal_examiner: examiner, category: 'internal'
}, ['number', 'parent$DISPLAY', 'internal_examiner$DISPLAY'])
.orElse({
number: 'Null',
parent$DISPLAY': 'Null',
internal_examiner$DISPLAY: 'Null'
});
gs.warn(JSON.stringify(result));
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 04:08 AM
Hi @Colleen
Include .orElse in your script. As per porduct doc, getBy method returns an optional object and it must include .orElse
var tps = '9ae4fc341b835e500d6b2131b24bcbed', examiner = '6b50e0560a0aa007000e4447ebea7f12';
var result = new global.GlideQuery('x_uob15_tps_examiner_nomination').getBy({
parent: tps, internal_examiner: examiner, category: 'internal'
}, ['number', 'parent$DISPLAY', 'internal_examiner$DISPLAY'])
.orElse({
number: 'Null',
parent$DISPLAY': 'Null',
internal_examiner$DISPLAY: 'Null'
});
gs.warn(JSON.stringify(result));
Hope this helps.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 04:22 AM
That worked. Thanks.