Need to automate masking the DOB in incident long description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 06:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 12:34 AM
Hello @Madhu51
For DOB you can utilize below javascript code:
var longDescription = inputs.long_description;
// Regular expressions for different date formats
var dobPatterns = [
/\b\d{2}\/\d{2}\/\d{4}\b/g, // MM/DD/YYYY
/\b\d{2}\/\d{2}\/\d{4}\b/g, // DD/MM/YYYY
/\b\d{4}-\d{2}-\d{2}\b/g // YYYY-MM-DD
];
var maskedDescription = longDescription;
// Mask each pattern
dobPatterns.forEach(function(pattern) {
maskedDescription = maskedDescription.replace(pattern, '**/**/****');
});
var masked_description = maskedDescription; // use this variable for output of your script and set it on record as per your requirement.
gs.print(masked_description);
Test Result:
Input =
1) User's date of birth is 01/23/1980 and they are facing login issues.
2) User's date of birth is 23/01/1980 and they are facing login issues.
Output =
1) User's date of birth is **/**/**** and they are facing login issues.
2) User's date of birth is **/**/**** and they are facing login issues.
Similarly for SSN check it can be done as below:
var longDescription = inputs.long_description;
// Regular expression to match SSNs with or without dashes and spaces, and embedded within text
var ssnPattern = /(\b|\D)\d{3}[- ]?\d{2}[- ]?\d{4}(\b|\D)/g;
// Mask SSNs in the long description
var maskedDescription = longDescription.replace(ssnPattern, function(match) {
return match.replace(/\d{3}[- ]?\d{2}[- ]?\d{4}/, '***-**-****');
});
var masked_description = maskedDescription;
gs.print(masked_description);
Test Result:
Input:
1) User reported an issue with their account. SSN: 123456789 needs to be verified.
2) User reported an issue with their account. SSN: 123-45-6789 needs to be verified. Another SSN: 987-65-4321 was also mentioned.
3) User's SSN123-45-6789 needs to be verified.
Output:
1) User reported an issue with their account. SSN: ***-**-**** needs to be verified.
2) User reported an issue with their account. SSN: ***-**-**** needs to be verified. Another SSN: ***-**-**** was also mentioned.
3) User's SSN***-**-**** needs to be verified.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 01:44 AM
masking SSN or DOB in field via flow designer?
if you mask them then how will agent know the details and how they can work?
check this article and enhance your script if you are using flow
Masking Sensitive PII data (aka SSN) in ServiceNow Fields
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader