Field map Regex

CátiaA
Tera Contributor

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

Ankur Bawiskar
Tera Patron
Tera Patron

@CátiaA 

can you share what's coming in both the source variables?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader