Mask SSN

daggupati
Tera Contributor

Hi Everyone,

I want to mask First 5 digits of ssn in my custom application table. I tried new SNC.Regex('/\[0-9]{3}-\[0-9]{2}-/'); as per the service now doc SNC.Regex API is not work on custom applications. So i tried standard regular expression for that also it is not working. Any other suggetions.

 

(function executeRule(current, previous /*null when async*/) {
var rgx = /(?:\d{3}|\(\d{3}\))([-\/\.])\d{2}/g;
var result = current.description;
var matched = rgx.test(result);
if (matched) { // This condition also satisfied but it is not replacing may be issue with .replace
current.description = rgx.replace(result,"###-##-");}
})(current, previous);

 

Thanks

2 REPLIES 2

Erik Stolberg
Tera Guru

Don't bother with the SNC.Regex... "When you upgrade to Eureka Patch 5 or later releases, you should convert scripts that use the SNC.Regex API to use regular JavaScript expressions." (Reference)

Also: "The SNC.Regex API is not available for scoped applications. For scoped applications, remove the SNC.Regex API and use standard JavaScript regular expressions." (Reference)

This worked for me in a business rule:

var rgx = new RegExp('^\\d{3}-{1}\\d{2}-{1}(?=\\d{4})', 'jg');
var result = current.description;
var matched = rgx.test(result);
	
if (matched) {
	current.description = result.replace(rgx, '###-##-');
}

Please remember to mark as helpful or correct answer if I've answered your question.