How can I query sys_email table in Scripts - Background

irenechen
Mega Contributor

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

12 REPLIES 12

Hi Irene, try the following:



var email = new GlideRecord('sys_email');


email.addEncodedQuery('subjectLIKEBCM Governance Declined');


email.query();


while(email.next()){


  gs.print(email.recipients);


}


Hi Berny,



The script run completed without data print out on the screen. The output


shows as below:


12 Script completed: script


Is there other option or configuration item need to turn on ?



Thanks,



Irene


Hi Irene,



Does the email truly contains the string: BCM Governance Declined?



If you're not getting any records it's then because the subject may be different.



One additional note, make sure that your elevated privileges session has not expired. Not getting any records could also be a result of having an expired elevated priv session.



Thanks,


Berny


Hi Berny,



The list can be extract from the UI by the export function, The


scrip-backgound can't output any data on the sys_email table, however, I


have tried different query. Is there any properties that configure this


table not be query?



Thanks,



Irene


Hi Irene, not at all. You should be able to query sys_email from any script using a GlideRecord


Try the following and please let me know how it goes.



var email = new GlideRecord('sys_email');


email.query();


while(email.next()){


  gs.print(email.sys_id);


}