Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2018 04:16 PM
Hi ryadavalli,
If you are running this in a scheduled job you will need to use gs.info rather than gs.log. The script will fail if you use gs.log.
A better approach to return a count of transactions would be to use GlideAggregate. This is much more efficient to execute, especially on large data sets. I've created a code snippet below to demonstrate GlideAggregate.
//use GlideAggregate rather than iterating through results to get a count.
var ga = new GlideAggregate("v_cluster_transaction");
ga.addQuery("age", ">=", gs.getDurationDate('0 0:0:1'));
ga.addAggregate("COUNT");
ga.query();
var transactionCount = 0;
if (ga.next()) {
transactionCount = ga.getAggregate("COUNT"); //return the aggregate count
//log only if the transaction count is 0 or below
if (transactionCount <= 0) {
//scheduled jobs should use gs.info rather than gs.log
gs.info(transactionCount + " Transactions were cancelled");
}
}
Let me know if it works for you.
Brent