0

I am trying to save a message which will be guided by ampscript for a single opt-in message. Am I doing something wrong?

%%[ SET @Row = LookupOrderedRows("SMSData_FromWeb_ToMC_Test",1,"DateTime Desc","MobileNumber",Mobile) 
SET @Card = Field(@Row,'CardNum') 
SET @FirstName = Field(@Row,'FirstName') 
SET @LastName = Field(@Row,'LastName') 
IF RowCount(@Row) > 0 THEN 
SET @Message = Concat('Thanks for subscribing ',@FirstName,' your Card Number is: ',@Card,' -- You'll get 4 msgs/Month. Rpl HELP for help. Rpl STOP to cancel. Msg&data rates may apply.') 
ELSE 
SET @Message = Concat('We're having trouble processing your request') ENDIF]%%
    %%=v(@Message)=%%
  • You'll need to provide more information, what kind of error are you getting and when. I also think you need to have your field functions after the if statement – EazyE Aug 8 '19 at 3:07
1

I've noticed few errors that might be the reason your code doesn't get loaded:

  1. in your "SET @Row" function, you've used "Mobile" as the value to build the WHERE clause. Try using MOBILE_NUMBER instead. Ampscript for sure associates this word with the phone number you're sending the SMS to.


  1. When you've used the "LookupOrderedRows" function, even though you've set it to return 1 row, it still returns a rowset. Therefore you must use the Row function to convert the rowset to a row object before you use Field:

    SET @Rows = LookupOrderedRows("SMSData_FromWeb_ToMC_Test",1,"DateTime Desc", 
    "MobileNumber",Mobile) 
    SET @Row = Row(@Rows, 1) /* Row Function */
    SET @Card = Field(@Row,'CardNum') 
    


  1. when you set @message, you're using single quotation marks even though you've used these to write "You'll" or "we're" within the quote, so the program identifies it as a closing quotation mark. Therefore, you should start and end your quote with double quotation marks:

    IF RowCount(@Row) > 0 THEN 
    SET @Message = Concat("Thanks for subscribing ',@FirstName,' your Card Number is: 
    ',@Card,' -- You'll get 4 msgs/Month. Rpl HELP for help. Rpl STOP to cancel. 
    Msg&data rates may apply.") 
    ELSE 
    SET @Message = Concat("We're having trouble processing your request") ENDIF]%%
    

If you fix these errors, your SMS configuration should work. Hope I could help.

| improve this answer | |
  • You're a savior! Thanks for all your help, this worked! – Alex Tejena Aug 8 '19 at 13:42
  • Additionally, for anyone looking at this, you need to engage support to enable Ampscript in your Mobile connect for your messages, otherwise you'll face an issue where it won't save the message with the ampscript. – Alex Tejena Aug 8 '19 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.