Mail script not working while trying to fetch GlideRecord from a non-task table using documet_id of approval record

rambo1
Tera Guru

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.

16 REPLIES 16

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

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

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.


AM24
Giga Guru

Hey did you ever find the solution to this? I'm having the same issue.

 

JEAN PHILIPPE D
Tera Contributor

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.


JEANPHILIPPED_0-1707129820234.png

 

That's ok here.
But we need to use it dynamically. If anyone has a solution.

 

JEANPHILIPPED_1-1707129884261.png