Approvers script ran but ServiceNow did not email the approver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2025 12:21 PM
Hello, all, and thanks in advance for the help! We have an existing flow (created in Workflow Editor) for HRIS that sends approval to ${opened_for.manager.manager} — but that is changing to "opened_for's third manager down from the CEO."
Since this is my first time scripting an approvers list, I pasted this into the Approvers script textbox as an experiment:
gs.log('Testing Level 3 Approver script');
answer.push('f7fc06e40f53d1002fdc9de692050e34');
The flow runs, the script runs—proven by the System Log—and the ticket state is Awaiting Approval, but the ticket's Approvers tab is empty and ServiceNow did not email a notice to the approver.
What did I miss?
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 02:48 AM - edited 06-04-2025 02:56 AM
Hi Tim,
as you mentioned ${opened_for.manager.manager} it means that the (3) Manager of the (2) Manager of the (1) Opened For would be the Approver.
You can check if such a logics is correct in your user hierarchy:
1) does the (2) manager of the opened for have a (3) manager field populated?
2) does the (3) approver (manager of the manager of the opened for) have valid email address?
3) is the (3) approver (manager of the manager of the opened for) active?
You can set it in the workflow using the activity as following:
1)
2)
3)
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 06:13 AM
Can you let us know what your script looks like? Since you said an approval record wasn't created (approvers tab is empty), you need to make sure you're creating an approval record in the sysapproval_approver table. Here is an example:
var approvalRecord = new GlideRecord('sysapproval_approver');
approvalRecord.initialize();
approvalRecord.state = 'requested';
approvalRecord.approver = '26295331312f3316624b4363'; //approver sysid
approvalRecord.source_table = 'sc_request'; //update this with your source table
approvalRecord.document_id = '3bc2d8see10444c80d8534360sbbff'; // request sysid
approvalRecord.sysapproval = '3bc2d8see10444c80d8534360sbbff'; // request sysid
approvalRecord.insert();
If your notification isn't being sent, this can be caused my several reasons:
- User is inactive
- You're not passing the sys_id or email_address correctly
- How is your notification being sent? Event or Triggered?
- How is the Who will receive page configured?
Please provide screen captures of your notification, flow, and script so we can help you troubleshoot further!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 01:02 PM
Oh dang, Neil, the sample that pops up under Advanced just says Set the variable 'answer' to a comma-separated list of user ids... 🙄 Figured the rest would be handled by this million-dollar "no code" platform. 🤣
Thank you for writing back so quickly!
My "additional approvers" script was exactly this:
gs.log('Testing Level 3 Approver script');
answer.push('f7fc06e40f53d1002fdc9de692050e34'); //CIO's sys_id, hard-coded for this experiment
I attempted your (modified) code block in Scripts - Background:
// Experiment to create Level 3 approval record for HRC0063407 in
// THIS DOES NOT WORK YET
var approvalRecord = new GlideRecord('sysapproval_approver');
approvalRecord.initialize();
approvalRecord.state = 'requested';
approvalRecord.approver = 'f7fc06e40f53d1002fdc9de692050e34'; //CIO's sys_id, hard-coded for this experiment
approvalRecord.source_table = 'sn_hr_core_case_operations'; //HRIT Operations Case Table
approvalRecord.document_id = '3D93e59b031b756694247c15cb234bcb92'; // sys_id for HRC0063407
approvalRecord.sysapproval = '3D93e59b031b756694247c15cb234bcb92'; // sys_id for HRC0063407
approvalRecord.insert();
The approvers list is still empty and System Log shows a lovely error, summed up as empty table name. I tried this:
var hrCase = new GlideRecord('sn_hr_core_case_operations');
if (hrCase.get('3D93e59b031b756694247c15cb234bcb92')) {
gs.info('Case found: ' + hrCase.u_title);
}
which resulted in this helpful message, same result in both Global scope and Human Resources: Core:
Source descriptor is empty while recording access for table sn_hr_core_case_operations: no thrown error
Security restricted: Read operation on table 'sn_hr_core_case_operations' from scope 'Global' was denied because the source could not be found. Please contact the application admin.
Security restricted: Read operation on table 'sn_hr_core_case_operations' from scope 'Global' was denied. The application 'Global' must declare a cross scope access privilege. Please contact the application admin to update their access requests.
What can be done?
-Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 01:45 PM - edited 06-04-2025 01:51 PM
That's strange because I use that exact background script to insert approvers on some of my requests on the fly in the case a flow errors out so that script for me works just fine. I just used it yesterday to add an approver to one of my requests.
What is the current State of the HR Case? Is it New or is it Assigned or Work In Progress?
What error popped up when you ran your background script?
Have you tried a different table name? Maybe try "sn_hr_core_case" instead?
This is what my results look like using that same script
It's possible you need to add a Restricted Caller Access Priviledge (RCAP) record since you're getting the 'read operation on table from scope was denied' error. This article might help
Solved: Re: Read operation on table 'sn_hr_core_case' from... - Page 2 - ServiceNow Community