- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-21-2020 06:57 AM
Hi,
I have a string such as
var str = "Hello Servicenow user Chinmayee Mishra.User user ID is : 1234s" ;
I have to find the ID and replace with another ID , lets say
var newStr = "Hello Servicenow user Chinmayee Mishra.Your user ID is : 987c";
The string length is not constant as the names can be different.
How do I do it ? Please help.
Thanks & Regards,
Chinmayee Mishra
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-21-2020 07:28 AM
refer below script
var str = "Hello Servicenow user Chinmayee Mishra.User user ID is : 1234s" ;
var substring = str.substring(str.indexOf("ID is : ") +8, str.length);
gs.info('->'+substring+'<');
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-21-2020 07:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-21-2020 07:06 AM
Hi Chinmayee,
you can use this:
var newStr = str.replace(str.split(" ").splice(-1), "987c");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-21-2020 07:18 AM
Thank you but the string length is not constant. the ID might not be at the end always. there might be other sentences too. The only similar string would be "user ID is :" .
Can you help please ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-21-2020 07:24 AM
ID will always remain at last right, even though string changes?