get row count
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 03:25 AM
Hi Frds,
The following script(s) use the function getRowCount() to count the number of records in a table. This can lead to performance issues on tables with undetermined number of rows. Instead of getRowCount(), I want to use GlideAggregate , could you pls help to modify the script for me. Thanks.
var ScopeChecker = Class.create();
ScopeChecker.prototype = { initialize: function() {
},
getSysIdByScopeName: function(scopeName) {
if (gs.nil(scopeName) || "global" == scopeName)
return null;
var gr = new GlideRecord("sys_store_app");
if (!gr.isValid())
return null;
gr.addQuery("scope", scopeName);
gr.query();
if (gr.next() && gr.getRowCount() == 1)
return gr.sys_id.toString();
return null;
},
isStoreApp: function(scopeName) {
var sys_id = this.getSysIdByScopeName(scopeName);
return !gs.nil(sys_id); },
type: 'ScopeChecker' };
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 03:38 AM
Is it a scoped application ? Try below:-
var ScopeChecker = Class.create();
ScopeChecker.prototype = { initialize: function() {
},
getSysIdByScopeName: function(scopeName) {
if (gs.nil(scopeName) || "global" == scopeName)
return null;
var gr = new GlideAggregate("sys_store_app");
if (!gr.isValid())
return null;
gr.addQuery("scope", scopeName);
gr.addAggregate('COUNT');
gr.query();
if (gr.next() && gr.getAggregate('COUNT') == 1)
return gr.sys_id.toString();
return null;
},
Scoped GlideAggregate API Reference - ServiceNow Wiki
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2016 03:39 AM
Hi,
Try below.
var gr= new GlideAggregate('sys_store_app');
gr.addQuery("scope", scopeName);
gr.addAggregate('COUNT');
gr.query();
var result= 0;
if (gr.next())
result= gr.getAggregate('COUNT');
Instead of using GlideRecord.
Regards,
Karthik Nagaramu