- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 05:36 AM
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var approver = new GlideRecord('sysapproval_approver');
approver.addQuery('sysapproval', current.sys_id);
approver.query();
if (approver.next()) {
out.print("Aprovador Designado: " + approver.approver.getDisplayValue());
}
})(current, template, email, email_action, event);
I am creating a notification in the sc_req_item table, but I need to insert the approver in this notification. As I am unable to do dot walking, I am trying to insert the approver through an email script. When inserting the email script in my notification, it is going blank. I believe my code has an error. Could someone help me with this issue?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 05:42 AM
try this
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var approver = new GlideRecord('sysapproval_approver');
approver.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
approver.query();
if (approver.next()) {
template.print("Aprovador Designado: " + approver.approver.getDisplayValue());
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2025 10:01 PM
Hi @Ariomar de Deus ,
Use below email script and make sure that your ritm should have at least one approval record.
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
if (gr.next()) {
template.print("Approver : " + gr.approver.getDisplayValue());
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 05:42 AM
try this
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var approver = new GlideRecord('sysapproval_approver');
approver.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
approver.query();
if (approver.next()) {
template.print("Aprovador Designado: " + approver.approver.getDisplayValue());
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2024 08:33 AM
didn't work, the approver doesn't appear in the notification

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2025 09:12 PM - edited ‎01-02-2025 11:45 PM
Hello @Ariomar de Deus , Good Day! I have tired your script in the explore with the sys-id in the query directly and it returns the approver name as expected. [ gs.print("Aprovador Designado: " + approver.approver.getDisplayValue());]
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var approver = new GlideRecord('sysapproval_approver');
approver.addQuery('sysapproval', current.sys_id);
approver.query();
if (approver.next()) {
template.print("Aprovador Designado: " + approver.approver.getDisplayValue());
}
})(current, template, email, email_action, event);
Could you please once add the logs in your script and try to trigger the notification on lower environment and verify the logs what exactly you are getting over there. (Observation: out.print is used intead template.print)
Please do let me know if it helps you and feel free to share your results if it is not working.
Thanks,
Priyanka R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2025 04:16 AM
the script I shared should work fine.
what debugging have you done so far?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader