Help with Pre-Map script
AnsweredI need to convert phone number from a string, ie 3334445555 into a formatted number, (333) 444-5555 in order to match customer in NetSuite.
My input data is:
"data": [
{
...
"Store Phone Number": "3334445555",
....
}
]
I don't understand how to pull out the phone number, alter and then pass it.
Has anyone done this? Help is much appreciated.
Brian
0
-
Official comment
Hi Brian,
This is Matt, head of Product at Celigo.
The following code iterates over each record in the data[] array and simply concatenates the pieces of the number with the additional characters. Hope this helps.
-Matt
Try this:
function convertPhoneNumber (options) {
options.data.forEach(function(i) {
let tmp = i["Store Phone Number"]
i.cleanNumber = "(" + tmp.substring(0,3) + ") " + tmp.substring(3,6) + "-" + tmp.substring(6,10)
})
return {
data: options.data,
errors: options.errors
}
}
The following sample:
{
"errors": [],
"data": [
{
"Store Phone Number": "3334445555"
},
{
"Store Phone Number": "1234567890"
}
]
}
Yields:
{
"data": [
{
"Store Phone Number": "3334445555",
"cleanNumber": "(333) 444-5555"
},
{
"Store Phone Number": "1234567890",
"cleanNumber": "(123) 456-7890"
}
],
"errors": []
} -
Hi Matt,
Thank you for your help.
Brian
0
Please sign in to leave a comment.
Comments
2 comments