The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Need to automate masking the DOB in incident long description

Madhu51
Mega Contributor

Hello All,

 

We have the below catalog form and based on the input provided by user, we need to mask SSN or DOB from incident long description using flow designer. Could you please suggest some sample scripts for the same.

 

Thanks in adavance

2 REPLIES 2

Viraj Hudlikar
Tera Sage

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.

Ankur Bawiskar
Tera Patron
Tera Patron

@Madhu51 

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.

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