Field map Regex
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 04:37 AM
Hi,
I'm trying to transform a field through regex on a field map on transform map:
This is the script:
(function transformEntry(source) {
var platform = source.u_platform;
var correlationId = '';
try {
var vmId = JSON.parse(source.u_originalresource);
} catch (e) {
gs.error("Failed to parse u_originalresource: " + e.message);
return correlationId;
}
if (platform == 'AWS') {
var awsInstanceId = vmId['awsInstanceId'];
if (awsInstanceId) {
var regex = /instance\/(i-\w+)/;
var match = awsInstanceId.match(regex);
if (match && match[1]) {
correlationId = match[1];
} else {
gs.error("AWS instance ARN format is incorrect: " + awsInstanceId);
correlationId = '';
}
} else {
gs.error("AWS Instance ID (awsInstanceId) not found in u_originalresource");
correlationId = '';
}
} else {
correlationId = source.u_originalresource_id;
}
return correlationId;
})(source);
The variable awsInstanceId I could populate it fullly eg: "arn:aws:ec2:eu-central-2:490636997576:instance/i-0365609510988841b" but with the regex logic it does not update the field to just "i-0365609510988841b", and that's what I intended to do.
Can you help? I can't see no logs from this. Thank you
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 06:45 AM
can you share what's coming in both the source variables?
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader