Replace GlideRecord with GlideAggregate and a 'COUNT' aggregate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 02:48 AM
Hi All ,
I have a requirement where I want to replace GlideRecord with GlideAggregate and a 'COUNT' aggregate , How can I do it
The functionality of the code should not be changed , I just want to replace GlideRecord with GlideAggregate and a 'COUNT' aggregate basically to get rid of the getRowCount()
Code Snippet :
else if (Type == 'glide_list') {
var reference = descript.getReference();
var encodedQuery = "nameIN' + value + '^ORsys_idIN' + value";
if (key == 'watch_list') {
reference = 'sys_user';
encodedQuery = 'active=true^sys_idIN' + value + '^ORuser_nameIN' + value + '^ORemailIN' + value;
} else if (key == "group_list") {
reference = 'sys_user_group';
encodedQuery = 'active=true^nameIN' + value + '^ORsys_idIN' + value;
}
var gr = new GlideRecord(reference);
gr.addEncodedQuery(encodedQuery);
gr.query();
if (!gr.hasNext() || value.split(',').length != gr.getRowCount()) {
if (ignore) {
this.ignored[key] = value;
} else {
this.message = "Not a Valid value.";
this.detail = "Value '" + value + "' for '" + key + "' is not valid " + reference + " list.";
var myError = new sn_ws_err.ServiceError();
myError.setStatus(400);
myError.setMessage(this.message);
myError.setDetail(this.detail);
this.response.setError(myError);
return false;
}
} else {
var values = [];
while (list.next()) {
values.push(list.getUniqueValue());
}
this.data[key] = values.toString();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:53 AM
Check out this helpful post on understanding Aggregates
Or the Docs

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 03:53 AM
You could use the GlideQuery API (a wrapper for GlideRecord and GlideAggregate) and replace your query with
new global.GlideQuery.parse(reference, encodedQuery).count()
The above will return a count of the records found