if the Worknotes Comments has PII Data mask it on UI and at the Backend

SAS21
Tera Guru

Before work notes is updated by user, check for PII data in the Incident Comments and mask the card data and update the worknotes comments 

 

How can we achieve this via Before insert, update BR on Sys Journal field table ?  

Trying with the below. Appreciate the help if something is missing.

var regex= /27\d{2}[\-\s]?\d{6}[\-\s]?\d{5}/g;

if (!gs.nil(current.value)) {

var tableName = current.name;
var fieldName = current.element;
if (tableName == u_hd_incident && fieldName == 'u_comments') {

var result = value.match(regex);

if (result) {

var result= current.value;

var modifiedValue = result[i].replace(/[-\s]/g, '').replace(/^(\d{4})/, 'XXXX');
maskedData = maskedData.replace(new RegExp(result[i], 'g'), modifiedValue);

current.u_comments = maskedData;
}
}
}

 

 

1 ACCEPTED SOLUTION

Amitoj Wadhera
Kilo Sage

Hi @SAS21 ,

 

Here is the corrected code:

(function executeRule(current, previous /*null when async*/) {

    var regex = /27\d{2}[\-\s]?\d{6}[\-\s]?\d{5}/g;

    if (!gs.nil(current.value)) {
        var tableName = current.name;
        var fieldName = current.element;
        
        if (tableName == 'incident' && fieldName == 'comments') {
            var matches = current.value.match(regex);
            var modifiedValue = current.value;

            if (matches) {
                matches.forEach(function(match) {
                    var masked = match.replace(/[-\s]/g, '').replace(/^(\d{4})/, 'XXXX');
                    modifiedValue = modifiedValue.replace(new RegExp(match, 'g'), masked);
                });
                
                current.value = modifiedValue;
                current.work_notes = "PII data was detected and masked in the comments.";
            }
        }
    }

})(current, previous);

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Thanks,

Amitoj Wadhera

View solution in original post

3 REPLIES 3

Amitoj Wadhera
Kilo Sage

Hi @SAS21 ,

 

Here is the corrected code:

(function executeRule(current, previous /*null when async*/) {

    var regex = /27\d{2}[\-\s]?\d{6}[\-\s]?\d{5}/g;

    if (!gs.nil(current.value)) {
        var tableName = current.name;
        var fieldName = current.element;
        
        if (tableName == 'incident' && fieldName == 'comments') {
            var matches = current.value.match(regex);
            var modifiedValue = current.value;

            if (matches) {
                matches.forEach(function(match) {
                    var masked = match.replace(/[-\s]/g, '').replace(/^(\d{4})/, 'XXXX');
                    modifiedValue = modifiedValue.replace(new RegExp(match, 'g'), masked);
                });
                
                current.value = modifiedValue;
                current.work_notes = "PII data was detected and masked in the comments.";
            }
        }
    }

})(current, previous);

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Thanks,

Amitoj Wadhera

Thank you. Its working

What does the regex look for?