Translate GlideQuery into GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi All,
I want to replace GlideQuery with Gliderecord, can someone please help me with the translation. Specially, with the 'select' query part
GlideQuery/ existing script :
Something similar as below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10m ago
There is nothing similar as "select" for GlideRecord. With GlideRecord you retrieve the whole record so you can just loop through it (while (screq.next())) and use screq.getValue("<field name>") to access the fields you would get from the select
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3m ago
var obj = {};
var screq = new GlideRecord('sc_req_item');
screq.addQuery('active', true);
screq.addQuery('cat_item.name', 'XYZ');
screq.addQuery('variables.recertid_new', 'ABC'); // catalog variable
screq.addQuery('approval', 'approved');
screq.addQuery('state', 'IN', [1, 2]);
screq.query();
while (screq.next()) {
// Access the fields directly – no .select() in GlideRecord
var number = screq.getValue('number');
var country = screq.u_beneficiary.u_country + ""; // dot-walked reference
gs.info("test " + number);
// Second query (equivalent to selectOne)
var brambleSource = new GlideRecord('u_country_to_request_type');
brambleSource.addQuery('u_bramble_source', 'IN', ['EMEA', 'APAC', 'TURKEY', 'Germany']);
brambleSource.addQuery('u_country_code.u_lookup_country', country);
brambleSource.query();
var result = null;
if (brambleSource.next()) {
result = brambleSource.getValue('u_bramble_source');
}
// If no match found, result stays null (same as orElse)
obj[number] = result;
}GlideRecord can’t use .select() or .selectOne(), so you query normally with while (gr.next()) and access the needed fields directly, then manually check the second table with another GlideRecord query.
