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

jaheerhattiwale
Mega Sage

@sirou Some times the string field returns the object, to make sure we get the string output we add toString().

 

Please mark as helpful based on impact.

 

If any other question regarding code please add full code with more info.

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

Hi @jaheerhattiwale 

I'm trying to put the "subject" in the description in inbound Email Actions.
The picture is the script I wrote.
However, this results in a value of "null"

Am I doing this wrong?

スクリーンショット 2022-12-20 153346.jpg

@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

Hi @jaheerhattiwale 

Thank you for your reply

your code solved the problem