- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 07:02 AM
Having trouble figuring out how to format the phone number field in the Data Source we use to update sys_user. We'd like to get the field to display in the format of (111) 222-3333 as it does when we manually update a user record.
Have tried using just 7 numerical digits but it then shows up as 1112223333. Have also tried a script but that produces a value of 'undefined'. (script example below). I am probably missing something simple and haven't been able to find much in way of documentation, so any help or suggestions are appreciate.
Script Used. Have also tried it without the space after the parentheses surrounding the area code field but no joy with that either.
answer = (function transformEntry(source) {
var phoneStr = source.u_phone.toString();
if (phoneStr == '') {
target.u_phone = ''}
else {
gs.log('user import transform phone from sql is: ' + phoneStr);
target.u_phone = formatPhone(source.u_phone);
}
function formatPhone(phoneString) {
var area_code = phoneString.slice(0, 3);
gs.log('user import transform area code for phone ' + phoneString + ' is ' + area_code);
var first_three = phoneString.slice(3, 6);
gs.log('user import transform first three for phone ' + phoneString + ' is ' + first_three);
var last_four = phoneString.slice(6, 10);
gs.log('user import transform last 4 for phone ' + phoneString + ' is ' + last_four);
var formattedPhone = "(" + area_code + ") " + first_three + "-" + last_four;
gs.log('user import transform formatted number for phone ' + phoneString + ' is ' + formattedPhone);
return formattedPhone;
}
})(source);
Thanks in advance.
Jeff
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 02:49 PM
It is used as a Field map script in the data source transform. u_phone is the incoming data in the Import Set. Your question though made me re-review it, and it was a stupid omission on my part. I just added ' return target.u_phone' and it works fine now. working script below.
answer = (function transformEntry(source) {
var phoneStr = source.u_phone.toString();
if (phoneStr == '') {
target.u_phone = ''
} else {
gs.log('user import transform phone from sql is: ' + phoneStr);
target.u_phone = formatPhone(source.u_phone);
gs.log('target.u_phone for phone ' + phoneStr + ' is ' + target.u_phone);
}
return target.u_phone
function formatPhone(phoneString) {
var area_code = phoneString.slice(0, 3);
gs.log('user import transform area code for phone ' + phoneString + ' is ' + area_code);
var first_three = phoneString.slice(3, 6);
gs.log('user import transform first three for phone ' + phoneString + ' is ' + first_three);
var last_four = phoneString.slice(6, 10);
gs.log('user import transform last 4 for phone ' + phoneString + ' is ' + last_four);
var formattedPhone = "(" + area_code + ") " + first_three + "-" + last_four;
gs.log('user import transform formatted number for phone ' + phoneString + ' is ' + formattedPhone);
return formattedPhone;
}
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 08:10 AM
Hi,
I have no idea where that script is used, business rule, clident script, script include,... But from what I see you convert 'u_phone' to a string in line 3, but then pass 'u_source' to formatPhone() and do not pass 'phoneStr'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 02:49 PM
It is used as a Field map script in the data source transform. u_phone is the incoming data in the Import Set. Your question though made me re-review it, and it was a stupid omission on my part. I just added ' return target.u_phone' and it works fine now. working script below.
answer = (function transformEntry(source) {
var phoneStr = source.u_phone.toString();
if (phoneStr == '') {
target.u_phone = ''
} else {
gs.log('user import transform phone from sql is: ' + phoneStr);
target.u_phone = formatPhone(source.u_phone);
gs.log('target.u_phone for phone ' + phoneStr + ' is ' + target.u_phone);
}
return target.u_phone
function formatPhone(phoneString) {
var area_code = phoneString.slice(0, 3);
gs.log('user import transform area code for phone ' + phoneString + ' is ' + area_code);
var first_three = phoneString.slice(3, 6);
gs.log('user import transform first three for phone ' + phoneString + ' is ' + first_three);
var last_four = phoneString.slice(6, 10);
gs.log('user import transform last 4 for phone ' + phoneString + ' is ' + last_four);
var formattedPhone = "(" + area_code + ") " + first_three + "-" + last_four;
gs.log('user import transform formatted number for phone ' + phoneString + ' is ' + formattedPhone);
return formattedPhone;
}
})(source);