Mail script not working while trying to fetch GlideRecord from a non-task table using documet_id of approval record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 05:42 AM
var gr = new GlideRecord('u_capex_requests');
gr.get('sys_id', current.document_id);
template.print(gr.u_requestor_name);
tried this in mail script to get requestor name in email body, but it is not happening. Please suggest some alternatives to get requestor name in email body.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 01:06 AM
My approach to testing mail scripts:
1) Unit test the code in a script testing tool,
//Use this code to unit test output first in fix script/background script/xplore, remove after
var template = [];
template.print = function(msg) {gs.print(msg);}
//Actual code
var gr = new GlideRecord('u_capex_requests');
if ( gr.get('sys_id', current.getValue('document_id')) ) {
template.print(gr.u_requestor_name);
} else {
template.print('Unknown requestor');
}
2) Remove dummy template function, put in mail script
3) Test using Preview Notification functionality
4) Test by triggering email, check email body
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 01:06 AM
I'm pretty sure there is another issue at play, never heard of that issue before.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2017 03:19 AM
I had tested whether the Glide query is working by trying to print the getRowCount() in email body. Did not add any "addQuery" filter. Just the following :
var gr = GlideRecord(<table name>);
gr.query();
template.print(gr.getRowCount());
Tried it on 'incident'. Printing the number of records alright ! But whenever used that custom non task table, it prints out 0.
I am only trying to find out some error if I can, throughout the system logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2023 11:26 AM
Hey did you ever find the solution to this? I'm having the same issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 02:48 AM
Good day everyone,
I met the same issue.
If insert directly for example the number of an incident: INCXXXX in GlideRecord.
I have the result.
But if i insert the variable in this GlideRecord. It's cannot fetch data.
That's ok here.
But we need to use it dynamically. If anyone has a solution.