How can I query sys_email table in Scripts - Background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 06:36 AM
Hi,
I need to extract some information from sys_email table while I am doing the production issue investigation, but when I run below scripts in the "scripts - background" tool, there's no data list out.
gs.sql("select distinct recipients from sys_email where sys_created_on= '2015-08-22' and subject like 'BCM Governance Declined%'");
Thanks in advance for your help!
Irene
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 06:40 AM
Hi Irene,
var email = new GlideRecord('sys_email');
email.addQuery('sys_created_on', '2015-08-22');
email.addQuery('subject', 'CONTAINS', 'BCM Governance Declined');
email.query();
while (email.next()) {
gs.print(email.recipients);
}
This script can also be run in the Scripts - Background module. However; if you want to use DISTINCT, GlideAggregate needs to be used instead of GlideRecord.
More about querying via GlideRecords/GlideAggregate:
Using GlideRecord to Query Tables - ServiceNow Wiki
GlideAggregate - ServiceNow Wiki
Does this help you forward?
Kind regards,
Stijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 06:53 AM
Hi Stijin,
Thanks your quick response. The script run without data print out.
The output screen only shows below information:
15 Script completed: script
Any other configuration need to turn on to enable the data list out?
Thanks again,
Irene
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 06:46 AM
Hi Irene, you can type sys_email.list in your navigation window and then you can filter down through the list of records that contain BCM Governance Declined. That will work better for your and will be a better approach to do troubleshooting in a production environment.
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2015 06:56 AM
Hi Berny,
Thank you for your information. I use the query in script as the UI list
doesn't show the full string value if it's too long. I need to extract
the information from the list to generate the report.
Irene