Stripped Phone Values

I’m not sure how to get the below to work. It doesn’t seem to like me using .split(). Can somebody point me in the right direction please?

const phoneArray = seller_lead_field_sellers_phone_number_iterable.split(“,”);
let strippedPhone = “”;

for (let i = 0; i < phoneArray.length; i++) {
strippedPhone += “,” + phoneArray[i].split(“:”)[1].replace(/\D+/g, ‘’).slice(-10);
}

strippedPhone.replace(/^,/, ‘’);

@Martin_E

Does anything here:

Help you?

Hey Jason,

That’s close but how would you get it to loop through each number and provide a comma separated string of the result?

I have the same issue as Andrew. I’ve been using PHP in Globiflow for so long that coming over to Javascript is somewhat foreign but I think I’ll get it once I’ve seen a few examples of how the pros would do it.

Another quick question I had is, whats the difference/when would you use a ‘Perform a Calculation’ vs ‘Execute a Script’?

I managed to get it working. Thanks!

Would still be interested in your answer around ‘Perform a Calculation’ vs ‘Execute a Script’ though!

3 Likes

That is an interesting question there is a bit of chat about it here: [✅ Solution] Best practice script or calculation in automations - #3 by Tim

However,
The ‘Perform a Calculation’ I use for my simple scripts ‘one-liners’ and I think most importantly where there is only a single output variable

The ‘Execute a Script’ I use for more complex things and where the output is multiple variables.

Looking at the automation I have open right now:

I could do that ‘replyAdd’ calc at the top of the script but it is used further down the automation as well as in the script so it seems easier to do it in a separate calculation.

I think there is somethings (other than multiple output variables) that a ‘Perform a Calculation’ can’t do but I couldn’t list them, honestly, I just go on my gut and what feels most helpful :wink:

What I do like which I think sometimes gets missed is being able to run the calculation within a Create or update record block:

1 Like

Got it. Thank you!

Having a small issue with the above that it doesn’t actually add the value in the field. It will actually unset the field value if there is already a value there. Am I missing something obvious?