- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 09:18 AM
Hey All,
I have an email script that works properly when I run it via the background script, but when I preview it for the email notification, it isn't working.
My email notification is running off the change_request table, but I'm using the sysapproval_approver table for my GlideRecord query.
Below is my script:
var gr = new GlideRecord("sysapproval_approver");
gr.get(current.sysapproval);
template.print("This is the approver who is rejecting the change request: " + gr.approver.getDisplayValue() + " from " + gr.group.assignment_group.getDisplayValue() + " has rejected this change. Please see rejection comments below and contact " + gr.approver.getDisplayValue() + " if you have questions. ");
But when I preview the notification, I get this:
What am I doing wrong? Am I missing something? Does the method get no longer work? I'm confused b/c it is working as expected via the background script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 10:53 AM
If the notification is on the change request table, the "current" object will be referencing the change request record triggering the notification. So current.sysapproval is not valid since there is no sysapproval field on change request.
So you need to use something like
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id', current.sys_id);
gr.addQuery("state", "rejected"); // Filter out only approved record if you want all comment this line
gr.query();
if(gr.next()){
template.print("YOUR CONTENT GOES HERE");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 09:44 AM
Try gr.getDisplayValue('approver') or gr.approver.name
and use gr.group.assignment_group.name
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 09:45 AM
Hi @Community Alums can you Replace the
gr.get(current.sysapproval) to below
gr.addQuery('sysapproval', current.sys_id);
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 09:46 AM
In your query, current is the change_request table. Hence your filter needs to be:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 10:05 AM
Also as suggested by others, you need to query by the sysapproval. Also you may need to add another addQuery, if you want to only show approval with Rejected state.
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('sysapproval', current.getValue('sys_id'));
gr.query();
if (gr.next())
{
template.print("This is the approver who is rejecting the change request: " + gr.getDisplayValue('approver') + " from " + gr.group.assignment_group.name+ " has rejected this change. Please see rejection comments below and contact " + gr.approver.name + " if you have questions. ");
}
Please mark this response as correct or helpful if it assisted you with your question.