The CreatorCon Call for Content is officially open! Get started here.

how toString() is used

sirou
Tera Contributor

hello everyone

 

I have a question about how toString() is used

 

var s = sys_email.sys_id;
var mm = s.subject.toString();
var reg = /\[[0-9]+\]/;
var result = (mm.match(reg) + "").match(/[0-9]+/)+ "";

 

Why can't this script extract the number from the email subject line?

 

1 ACCEPTED SOLUTION

@sirou You dont need to do GlideRecord on email table.

 

email object itself is gliderecord object.

 

var s = email.subject.toString();

 

The above line should give you subject. dont query email table

 

Replace line 3,4,5,6,7 with above line

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

7 REPLIES 7

👍

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hi @sirou ,

 

Always try to use toString() or +"" when we GlideRecord any table and use sys_id.

EmailRec.sys_id.toString() / EmailRec.sys_id+""

 

You can also use getUniqueValue()

EmailRec.getUniqueValue().toString() / EmailRec.getUniqueValue()+""

 

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**

 

Maik Skoddow
Tera Patron
Tera Patron

Hi

the correct code is (assuming that sys_email is a variable holding a GlideRecord on table sys_email)

 

var mm = sys_email.getValue('sys_id');
var reg = /\[[0-9]+\]/;
var result = (mm.match(reg) + "").match(/[0-9]+/)+ "";

 

Maik