- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 12:32 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 04:35 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 12:51 AM - edited 04-17-2024 01:01 AM
Hi @SK41
You can use filters to do that easily. BTW, for script, can you check this-
var id = fd_data.trigger.current.case; //You need to get the sys_id first.
gs.info("id is" + id);
if (id) {
var emailCheck = new GlideRecord('sys_email');
emailCheck.addQuery('instance', 'CONTAINS', id); //This stores the sys_id. So id should contain sys_id only.
emailCheck.query();
if (emailCheck.hasNext()) {
gs.info("Email found for incident: " + id);
return true;
} else {
gs.info("No email found for incident: " + id);
return false;
}
} else {
gs.info("Incident number is empty.");
return false;
}
Please share the logs to debug if this approach fails.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 01:12 AM
This is not working. I think we cannot query the simple way as the target field in sys_email table is of document_id type. That is why the query is not working. Is there a way to query the document_id type field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 01:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 09:00 AM
Hi @SK41
The query is fine. It's just that you need to use the sys_id as it is reference field which I have already mentioned in the comments. I had tried above with sys_id in background script and that worked.
Please mark my answer helpful and correct.
Regards,
Amit