0

I am using the following code to format a phone number in the data extension like 1234567890 to a phone number formatted like (123) 456-7890. My AMPscript is as follows %=Format(Agent Phone Number,"(###) ###-####")=%%

and I'm getting the following error when I try to generate a subscriber preview:

An error occurred when attempting to evaluate a ContentBlockByID function call. Function Call: ContentBlockById("923944") See inner exception for details.

An error occurred when attempting to resolve a function call. See inner exception for detail. Function Call: Format(Agent Phone Number,"(###) ###-####") Index: 585 TransCode Type: HTML Content Type: HTML Substitution Level: Subscriber Message Context: Preview

Invalid characters appear at the end of the parameter value Function Call: Format(Agent Phone Number,"(###) ###-####") Parameter Value: Agent Invalid Character: P

Any ideas for a fix?

1 Answer 1

1

Since your send context variable contains spaces, you'll need to reference it differently. I'd suggest setting a variable for it and doing some checking in a block with AttributeValue and ReplaceList:

%%[

set @AgentPhoneNumber = AttributeValue("Agent Phone Number")

/* for testing */ 
set @AgentPhoneNumber = "+(123) 4567-890"

output(concat("<br>AgentPhoneNumber: ", @AgentPhoneNumber))

if not empty(@AgentPhoneNumber) then 

    /* replace common non-numeric characters */
    set @AgentPhoneNumber = replaceList(@AgentPhoneNumber,""," ","(",")","-","+")
    output(concat("<br>AgentPhoneNumber: ", @AgentPhoneNumber))
    set @AgentPhoneNumber = format(@AgentPhoneNumber,"(###) ###-####")

endif

]%%
<hr>Agent Phone Number: %%=v(@AgentPhoneNumber)=%%

Output

AgentPhoneNumber: +(123) 4567-890
AgentPhoneNumber: 1234567890
Agent Phone Number: (123) 456-7890

Test

https://mcsnippets.herokuapp.com/s/eqSlpGCM

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .