- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 09:24 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 10:38 PM - edited 12-19-2022 10:40 PM
@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.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 10:57 PM
👍
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 10:42 PM
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**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 09:54 PM
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