Skip to main content

Hello!

 

How to mask data field in IFS assyst?

 

i.e.

EmpNo- 12345678 should be masked as XXXXX6789.
 

Only the last 4 digits of EmpNo should be visible.

 

Appreciate if any expert who can help on this.

I am not sure of any native way of doing this (if there is I haven't found it) but have a workaround of sorts.

We have some custom fields on the ContactUsr form that are duplicates of some of the each other and control access through visibility as a proof of concept at the moment.

 

Populate both fields from the ETM import and manipulate the data with a replace function for the masked field.

Example below…

 


Hi,
I realize this is an old question, but in case it’s still open, or if someone else stumbles upon this post wondering the same thing:

The issue with masking is mostly related to handling UTF-8 characters, which ETM’s version of ECMAScript (5.1) does not have native methods for when it comes to splitting graphemes.

However, I’ve attempted to create a 5.1-compatible grapheme splitter and used it within a masking function. This got a bit out of hand, and ended up growing into a modular function with inputs for the text to be masked, mode (full, center, left, right), and the number of characters to remain visible 😅.

The main issue is that I haven’t been able to prove it will work with every input string and one known limitation such as emojis that consist of characters clustererd by a ZWJ (flags, skin tone modifiers etc). However it should work as masking tool for most general situations. 

 

function (input, mode, visibleChars) {

// Default visible characters
if (typeof visibleChars === 'undefined') {
visibleChars = 2;
}

// Validate visibleChars
if (visibleChars < 0) {
logger.error("Negative visibleChars not allowed.");
return "";
}

// Grapheme splitter (basic polyfill for ECMAScript 5.1)
function splitGraphemes(str) {
// Attempt at ECMAScript 5.1-safe splitting of surrogate pairs (does not work for emojis with ZWJ etc)
var result = [];
for (var i = 0; i < str.length; i++) {
var charCode = str.charCodeAt(i);
// Check for high surrogate
if (charCode >= 0xD800 && charCode <= 0xDBFF && i + 1 < str.length) {
var nextCharCode = str.charCodeAt(i + 1);
// Check for low surrogate
if (nextCharCode >= 0xDC00 && nextCharCode <= 0xDFFF) {
result.push(str.substr(i, 2));
i++; // Skip next char to avoid double counting
continue;
}
}
result.push(str.charAt(i));
}
return result;
}

var chars = splitGraphemes(input);
var length = chars.length;

if (mode === "full" || (mode === "center" && visibleChars === 0)) {
return new Array(length + 1).join("*");
}

if (mode === "left") {
if (visibleChars >= length) {
logger.warn("Left mask failed: mode=left, length=" + length + ", visibleChars=" + visibleChars);
return "";
}
return new Array(length - visibleChars + 1).join("*") + chars.slice(length - visibleChars).join("");
}

if (mode === "right") {
if (visibleChars >= length) {
logger.warn("Right mask failed: mode=right, length=" + length + ", visibleChars=" + visibleChars);
return "";
}
return chars.slice(0, visibleChars).join("") + new Array(length - visibleChars + 1).join("*");
}

if (mode === "center") {
var totalVisible = visibleChars * 2;
if (totalVisible >= length) {
logger.warn("Center mask failed: mode=center, length=" + length + ", visibleChars=" + visibleChars);
return "";
}
var left = chars.slice(0, visibleChars).join("");
var right = chars.slice(length - visibleChars).join("");
var masked = new Array(length - totalVisible + 1).join("*");
return left + masked + right;
}

logger.error("Unknown masking mode: " + mode);
return "";
}


If placed inside a variable field, this function can then be called multiple times within the datamapper using: variables.maskString(input, mode, visibleChars); Or from later datamappers using: mapped[0].variables.maskString(input, mode, visibleChars);
(This mapped[0] example assumes the function is defined in a maskString variabel in the first datamapper in the channel.)

Example testing norwegian characters and “basic” emojis: 

var input = "Dette er en test tekst øæåøæ⚠️åæøåæ⚡øåæ";
var mode = "left";
var visibleChars = 4;
variables.maskString(input, mode, visibleChars);

 

There’s probably a more elegant way to do this, but it should work for masking simple strings and might serve as a starting point for a more robust method.

I’d love to hear from anyone if there are ideas for improvements or alternative approaches!

Best regards,
Richard