- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
// Build the GlideRecord query
var obj = {};
var scReqGR = new GlideRecord('sc_req_item');
scReqGR.addQuery('active', true);
scReqGR.addQuery('cat_item.name', 'XYZ'); // Catalog Item name
scReqGR.addQuery('variables.recertid_new', 'ABC'); // Catalog variable
scReqGR.addQuery('approval', 'approved');
scReqGR.addQuery('state', 'IN', '1,2'); // Multiple states
scReqGR.query();
while (scReqGR.next()) {
gs.info("test " + scReqGR.getValue('number'));
var country = scReqGR.u_beneficiary.u_country; // Reference field
var grBramble = new GlideRecord('u_country_to_request_type');
grBramble.addQuery('u_bramble_source', 'IN', 'EMEA,APAC,TURKEY,Germany');
grBramble.addQuery('u_country_code.u_lookup_country', country);
grBramble.query();
if (grBramble.next()) {
obj[scReqGR.number] = grBramble.getValue('u_bramble_source');
} else {
obj[scReqGR.number] = null;
}
}