Architect expression for phone number formatting failing on +1XXXXXXXXXX

Why does this setting in my Architect Data Action consistently return null or malformed output when trying to convert a E.164 string like +15551234567 into (555) 123-4567?

expression:
 type: "function"
 name: "formatPhoneNumber"
 args:
 - "{{contact.phoneNumber}}"
 - "(XXX) XXX-XXXX"

The function call isn’t throwing an error, but the result is empty. Am I missing a specific library import or is there a regex-based alternative expression that works reliably for this pattern?

As far as I remember, the Architect expression builder doesn’t support custom JS libraries like that, so you’ll need to use the built-in format function or a Data Action with a simple regex replace instead. Try switching to a JavaScript action in your flow to handle the string manipulation directly.

Warning: The formatPhoneNumber function isn’t a native Architect expression, which is why your output is null.

You need to drop that custom function approach entirely since it doesn’t exist in the runtime.

  • use replace with a regex like \+(\d)(\d{3})(\d{3})(\d{4}) to capture groups
  • map it to ($2) $3-$4 directly in the expression builder

expression:
type: “function”
name: “replace”
args:

  • “{{contact.phoneNumber}}”
  • “\+([0-9])([0-9]{3})([0-9]{3})([0-9]{4})”
  • “($1) $2-$3”
the `formatPhoneNumber` function doesn't exist in the standard runtime context. you're hitting null because the expression engine can't resolve that name. use the native `replace` function instead.

make sure to double-escape the backslashes in the regex pattern. architect expressions parse the string before passing it to the regex engine, so `\+` becomes `+` which matches any character. you need `\\+` to match the literal plus sign.

also, check the input string. if `contact.phoneNumber` contains spaces or dashes already, the regex won't match. add a `replace` step first to strip non-numeric characters except the leading plus. this approach is cleaner than injecting a custom JS action for simple formatting. keeps the flow declarative.