Need advice, Background script works fine in test but does not return results in production.

JR42
Giga Guru

Hi, I am trying to run the script below in my production environment, however, once the Running Transaction window closes, there are no results, and no link to the 'script execution history and recovery', just a blank window. 

In the lower environments, the script runs and prints the results just fine. 

It takes approximately 1200 seconds for the Transaction to run in production for 1 day.

 

Note: I have the same results when running for 1 day, 1 week, 1 month, 3 months.

 

Script:

var gr = new GlideRecord('sysevent_email_action');
gr.addEncodedQuery('active=true');
gr.query();
while(gr.next())
{
var count = 0;
// gs.print(gr.name);
var gr1 = new GlideRecord('sys_email_log');

gr1.addEncodedQuery('sys_created_onONLast day@javascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(0)');
gr1.query();
while(gr1.next())
{
//gs.print("gr: " +gr.sys_id);
//gs.print("gr1 :"+gr1.sys_id);

if(gr.sys_id == gr1.notification)
{
count++;
}
}
if(count!=0)
gs.print("Notification name: "+ gr.name + " Count: "+ count);

}

 

Any tips or advice to get this to print the output like it does in the dev/test environments would be greatly appreciated. 

 

 

Results in test:

Justin3_0-1703779401444.png

 

Results in Production

Justin3_1-1703779456976.png

 

7 REPLIES 7

Email retention 

 

Please check above linl

Sumanth16
Kilo Patron

Hi,

Do you have same access in prod like lower instances?

 

And check which scope you are running background script.

 

Thanks & Regards,
Sumanth Meda. 

Jim Coyne
Kilo Patron

Did you happen to try the GlideAggregate method @Isaias H mentioned in production?  That would be more efficient for your use case, but there might just be too much data.

 

I can select different conditions on the Created field in an actual report, so it's weird you can't. What version are you running?

 

There are a few other options that might work:

1. go to the sys_email_log table, add your conditions and group conditions and save it as a Favorite

2. same thing but save it it as a Personal Filter (available to you or others)

 

JimCoyne_0-1708062646877.png

 

3. create a Module for it.  This tool can help set it up for you: "Create a Module from this Query" Tool.  You just need to add "^GROUPBYnotification" to the Arguments field to Group the results by the Notification (have not added support for that yet).

 

I like to create an Application Menu for clients and add in little tidbits like "Quick Reports", etc... that might get used on a regular basis:

 

JimCoyne_1-1708062921859.png