Mask Phone Number Field in Transform Map

nrd5830
Mega Guru

We have a custom LDAP transform map. The phone number data pushed in to "Business Phone" field in the sys_user table from source import in the format xxx.xxx.xxxx. What I am trying to do is remove all special characters from source import and transform the data in the format as (xxx) xxx-xxxx.

How do I achieve this with Transform Map script, would it be an onBefore or onComplete or a Table transform script?

Mapping as follows,

Source Field - Target Field

u_telephonenumber (source)  - phone(sys_user)

 

1 ACCEPTED SOLUTION

Hi Raf,

 

PFB script which worked for me,

 

answer = (function transformEntry(source) {


var phoneNumber = source.u_business_phone; //source field


var digitOnlyRE = /\D/g;


var phoneNumberClean = phoneNumber.replace(digitOnlyRE, ''); // strip non-digit characters


if (phoneNumberClean.length == 11 && phoneNumberClean[0] == '1'){ // strip leading 1 if it exists


phoneNumberClean = phoneNumberClean.substring(1);


}


var phoneNumberFormatted = "(" + phoneNumberClean.substring(0,3) + ") " +

 

phoneNumberClean.substring(3,6) + "-" + phoneNumberClean.substring(6);


return phoneNumberFormatted;


}


)(source);

View solution in original post

7 REPLIES 7

Sorry for the typo, that should be set to "source" instead of "target"

var phoneNumber = source.u_phone + ''; // or g_form.getValue('phone') if in a client script
var digitOnlyRE = /\D/g;
var phoneNumberClean = phoneNumber.replace(digitOnlyRE, ''); // strip non-digit characters
// strip leading 1 if it exists
if (phoneNumberClean.length == 11 && phoneNumberClean[0] == '1'){
       phoneNumberClean = phoneNumberClean.substring(1);
}
// put into final format
var phoneNumberFormatted = "(" + phoneNumberClean.substring(0,3) + ") " + phoneNumberClean.substring(3,6) + "-" + phoneNumberClean.substring(6);
source.u_phone = phoneNumberFormatted;

Got it, will update you once I have this tested through LDAP import.

Hi Raf,

 

PFB script which worked for me,

 

answer = (function transformEntry(source) {


var phoneNumber = source.u_business_phone; //source field


var digitOnlyRE = /\D/g;


var phoneNumberClean = phoneNumber.replace(digitOnlyRE, ''); // strip non-digit characters


if (phoneNumberClean.length == 11 && phoneNumberClean[0] == '1'){ // strip leading 1 if it exists


phoneNumberClean = phoneNumberClean.substring(1);


}


var phoneNumberFormatted = "(" + phoneNumberClean.substring(0,3) + ") " +

 

phoneNumberClean.substring(3,6) + "-" + phoneNumberClean.substring(6);


return phoneNumberFormatted;


}


)(source);