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

ohhgr
Kilo Sage

Hi Kassandra,



You could achieve it using an onBefore Transform script.



code would be something like



target.u_phone = "("+source.u_phone.substring(0,3)+") "+source.u_phone.substring(3,10);




Hope that helps.




Thanks,


Mandar


ksmithdev
Mega Expert

Hi Mandar,



Thanks for your input! I tried to run it, it seemed to work with one record but then when I loaded in multiple, it is loading in as "2,394,939,432" as an example now.




Community Alums
Not applicable

I'm not sure how SN would respond to forcing an integer to parse like a string. Try this:



var phone = source.u_phone.toString();



target.phone = "(" + phone.substring(0,3) + ")" + phone.substring(4,10);


Hi Kassandra,



Also make sure you're using onBefore transform script that runs for each row in import set, and not onStart transform script that runs once for a whole import set.



Thanks,


Mandar