
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 07:55 AM
I'm needing to update the names of some assets and CIs by removing some ending characters. I need to look for ' - ' (that's space - space) and then remove the ' - ' plus the characters after that.
Have not had to do this before, still looking into it. Thanks in advance for the assistance!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:03 AM
Hi David,
You can do this by regEx and replace. Here is an example you can test and reuse pretty much:
var test = 'goran - remove this';
gs.debug(test.replace(/\s[-]\s.*/, ''));
//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:03 AM
Hi David,
You can do this by regEx and replace. Here is an example you can test and reuse pretty much:
var test = 'goran - remove this';
gs.debug(test.replace(/\s[-]\s.*/, ''));
//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:14 AM
I was going down the same path. Really appreciate the quick reply.
This is what I was testing successfully so far.
var text = 'test - remove';
gs.print(text.split(' - ')[0]);
What are your thoughts between the two?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 08:16 AM
Hi David,
the script looks fine
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
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
06-29-2020 08:19 AM
What are your thoughts between the two scripts listed? Pros/Cons? Just wanting to better understand.