Need some help troubleshooting
I am trying to format a phone number in a Genesys Cloud Architect flow. The incoming data from our webhook is a raw string like +15551234567. I need to transform this into (555) 123-4567 before passing it to an external API that requires specific formatting.
I am using the standard string manipulation functions available in the Architect Expression Editor. My current expression looks like this:
REPLACE(LEFT(REPLACE({trigger.data.phoneNumber}, "+", ""), 10), "", " ")
Wait, that’s not right. I tried a more complex nested approach based on some community examples:
CONCAT("(", SUBSTR({trigger.data.phoneNumber}, 3, 3), ") ", SUBSTR({trigger.data.phoneNumber}, 6, 3), "-", SUBSTR({trigger.data.phoneNumber}, 9, 4))
However, when I test this in the flow, the output is either empty or just () ---. The trigger.data.phoneNumber definitely contains +15551234567. I verified this by logging the raw value to a debug message.
I suspect the SUBSTR function in Genesys Cloud might be 1-based or handles the + sign differently than standard JavaScript or Python substrings. Also, I am not sure if the + needs to be stripped first using REPLACE before slicing.
Here is the JSON payload I am receiving:
{
"data": {
"phoneNumber": "+15551234567"
}
}
I have tried removing the + first:
SUBSTR(REPLACE({trigger.data.phoneNumber}, "+", ""), 2, 3)
This returns 555, which is correct. But chaining this for the whole format is causing syntax errors in the editor. The editor complains about invalid arguments.
Can someone provide a working expression that takes +1XXXXXXXXXX and outputs (XXX) XXX-XXXX? I am completely stuck on the syntax for the parentheses and hyphens.