Extract Numeric part from a particular string field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 05:13 AM
I wanted to extract numeric values from a given string in servicenow.
I wanted to implement it through Field Normalisation -> Transformations
I have created a transformation on a particular table(let's say Incident table) and on field(let's say short description field)
Consider my data is format :
sample1: User(13345)
sample2: 13345
sample3: 13345(User)
In any of the cases I need to extract Numeric part if it exists.
I have tried it using Transform Type as 'Replace'
Find: /regex/(/(\d+)/)
Replace: $0
Output required: 13345

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 05:22 AM
Hi,
Try below code.
var str = 'User(13345)';
var matches = str.match(/(\d+)/);
gs.info(matches);
Mark this as Helpful/Correct, if Applicable.
Regards,
Sourabh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 05:32 PM
Hi Vamsi,
There's also a need to check for when there's no numeric value.
function extractNumeric(str) {
var result = '';
var matches = str.match(/(\d+)/);
if (matches) {
result = matches[0];
}
return result;
}
gs.info(extractNumeric('User(123345)'));