The CreatorCon Call for Content is officially open! Get started here.

Transform Map Script to Change Integers to proper Phone Number formatting

ksmithdev
Mega Expert

Hi there!

 

Nice to meet your acquaintance. I am running into a problem where I have an excel spreadsheet that has numbers formatted like this "8107463849" on the Excel spreadsheet, but I need them to be imported into a String field as "(810) 746-3849" without the quotes, and with a space between the ) and the 7.

 

I have been trying to come up with a way to do it, but I can't seem to get anything to work. I was trying to run it Onstart, as a New Transform Map Script (not the first one you see on the Transform Map form). I also looked into researching setting up the Phone Number in the System Properties and setting it to True with the glide UI, but the instance I am working with does not want this global. They want it only for this specific field.

 

This is also in Dublin.

 

Does anyone have something that does this?

1 ACCEPTED SOLUTION

It is adaptable to a transform:



target.u_phone = formatPhone(source.u_phone);



function formatPhone(str) {  


var area_code = str.slice(0,3);  


var first_three = str.slice(3,6);  


var last_four = str.slice(6,10);


var ph = "(" + area_code + ")" + first_three + "-" + last_four;  


return ph;  


}  


View solution in original post

10 REPLIES 10

It depends on how you want to handle non-phone numbers in the phone field.   For us a blank phone number is okay.



To identify letters and strip out you can use a regex that identifies non-digits, and the replace method to remove them:


var phone_with_letters = 'A919EA-Gh5h5y5-013Zz4';


var phone_without_letters = phone_with_letters.replace(/\D+/g, '');


alert(phone_without_letters);//alerts 9195550134