Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Query with the incident number in the sys email table

SK41
Giga Guru

Hi, 

 

I have a requirement to check if I have received an email for the current incident. For this I am using glide record to query the sys_email table with current incident number to check if the email is there or not. I am searching the incident number in the target field of sys email but it seems query is not working. Could someone please help in resolving this?

Below is the code:

 

var id = fd_data.trigger.current.case;
gs.info("id is" + id);
if (id) {
var emailCheck = new GlideRecord('sys_email');
emailCheck.addQuery('instance', id);
emailCheck.query();
if (emailCheck.next()) {
return true;
} else {
return false;
}

 

Note: This script is used in flow to set the flow variable value.

Please suggest, how to fix it?

1 ACCEPTED SOLUTION

SK41
Giga Guru

Hi,

 

I was able to fix the issue by using sys id of the record as the query. Below code worked for me:

var id = fd_data.trigger.current.sys_id;
gs.info("id is" + id);
if (id) {
var emailCheck = new GlideRecord('sys_email');
emailCheck.addQuery('instance', id);
emailCheck.query();
if (emailCheck.next()) {
return true;
} else {
return false;
}

 

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @SK41 ,

Can you please refer below code 

var id = fd_data.trigger.current.case;
var idStr = id.toString();
if (id) {
var emailCheck = new GlideRecord('sys_email');
emailCheck.addQuery('instance', idStr);
emailCheck.query();
if (emailCheck.next()) {
gs.log('Inside IF');
} else {
gs.log('Inside Else');
}

 

Please reach me out if you need anything. 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

SK41
Giga Guru

Hi,

 

I was able to fix the issue by using sys id of the record as the query. Below code worked for me:

var id = fd_data.trigger.current.sys_id;
gs.info("id is" + id);
if (id) {
var emailCheck = new GlideRecord('sys_email');
emailCheck.addQuery('instance', id);
emailCheck.query();
if (emailCheck.next()) {
return true;
} else {
return false;
}