- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 03:05 PM
Trying to run a query against v_cluster_transaction table in a scheduled job, doesnt seem to be working. Same script is working if run as background script:
var transactionCount = 0;
var gr = new GlideRecord("v_cluster_transaction");
gr.addQuery("age", ">=", gs.getDurationDate('0 0:0:1'));
gr.query();
while(gr.next())
{
transactionCount++;
}
if(transactionCount> 0)
{
gs.log(transactionCount + ' Transactions were cancelled');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2018 12:32 PM
Did you change the Variable name to something other than gr ?
As i suggested in my First Reply.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 03:16 PM
do you see any error in progress worker of scheduled job after running this job?
How many records you get with your query?
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 03:22 PM
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2018 04:30 PM