- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2019 03:47 PM
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)
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 04:20 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2019 05:00 PM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2019 05:10 PM
Got it, will update you once I have this tested through LDAP import.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2019 04:20 PM
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);