Trying to format a phone number from +1XXXXXXXXXX to (XXX) XXX-XXXX in an Architect Data Action.
"formattedPhone": "(${field.phoneNumber.substring(3,6)}) ${field.phoneNumber.substring(6,9)}-${field.phoneNumber.substring(9,13)}"
The expression throws a syntax error on the parentheses. Is there a specific escape sequence required for the parentheses in Architect expressions?
The parentheses aren’t the issue here. It’s the string concatenation syntax. Architect expressions don’t handle inline string building with quotes like that. You’ll get a syntax error because the parser doesn’t know where the literal text ends and the function call begins.
You need to use the format function or stick to simple concatenation with explicit string literals. Here’s a cleaner way to do it using standard string manipulation functions that actually work in a Data Action:
"formattedPhone": "(${field.phoneNumber.substring(3,6)}) " + ${field.phoneNumber.substring(6,9)} + "-" + ${field.phoneNumber.substring(9,13)}
Wait, actually, even that can be tricky with mixed quotes. The safest bet is to avoid inline formatting entirely if you can, or use a pure function approach. But if you must do it inline, ensure your quotes are balanced. A better pattern I’ve seen in our routing rules is to just pass the raw number and let the downstream system handle the display format. Architect is really bad at complex string manipulation. If you need it formatted for a screen pop, do it in the script that receives the data, not in the flow. Saves a lot of headache with escaping characters.