Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

toString method not returning a string

Dom G
Tera Expert

 

I'm expecting for the below to return a string, but instead it's returning  a sysid. Can anyone see what I'm doing wrong?

 

var manager = current.variables.requested_for.manager.toString();

 

 

Thank you.

 

 

 

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, a reference record will return it's sys_id using toString().

try using getDisplayValue('fieldname');

https://developer.servicenow.com/dev.do#!/reference/api/quebec/server_legacy/c_GlideRecordAPI#r_GlideRecord-getDisplayValue?navFilter=getdisplay

bert_c
ServiceNow Employee
ServiceNow Employee

Reference fields contain the sys_id value of the record in the referenced table.  There is a 'getDisplayValue()' method in the GlideRecord class. That may help, but I see you are dot-walking for levels.  I haven't seen that scenario myself.

thomaskennedy
Tera Guru

// get an incident that refers to a printer
var gr = new GlideRecord('incident');
gr.addQuery('u_serial_number', '!=','' );
gr.query();
gr.next();
var sys_id = gr.sys_id;

// print the raw value of the reference column u_serial_number
gs.info( "1. " + gr.u_serial_number ); // "1. 004f47b1db90e014023fe66505961913"
gs.info( "1a. " + gr.u_serial_number.toString() ); // "1a. 004f47b1db90e014023fe66505961913"

// print the display value of the same column
gs.info( "2. " + gr.getDisplayValue('u_serial_number') ); // "2. Lexmark CX860dte"

Allen Andreas
Tera Patron

Hi,

"String" can be a sys_id...that's the JavaScript variable typeof classification.

So I think you may be using the wrong wording here, but you're looking for a manager name? Or something like that...so you'd have to dot-walk to that information otherwise, you're just retrieving reference field information from the requested_for's user record and their respective manager field.

You'd want use:

var manager = current.variables.requested_for.manager.name.toString();

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!