2

I would like to know on how to personalised SMS contents with AMPScript.

I have 2 Data Extensions where one Data extension has member information, and another that's been imported:

  • DE with SMS Contents

    Happy Birthday %%=v(@name)=%%! Kickstart your August Birthday staycation NOW!

I am unable to pull the respective member name with below AMPScript written.

Need some guidance.

%%[ 
VAR @language, @languages, @smsContent, @name, @names, @BatchSMSList7, @BatchSMSList7Record,@campaigncode, @message, @BatchSMSMessage7, @BatchSMSMessage7Record

Set @name = [cust_name]
Set @names = LookupRows("SCV_SF", "cust_id", cust_id)

IF RowCount(@names) > 0 THEN 
  Set @nameRecord = Row(@names,1) 
  Set @name = Field(@nameRecord,"cust_name") 
ENDIF 

set @language = [language]

IF empty (@language) THEN

    Set @language = "EN" 
    Set @languages = LookupRows("SCV_SF", "cust_id", cust_id)

    IF RowCount(@languages) > 0 THEN 
      Set @langRecord = Row(@languages,1) 
      Set @language = Field(@langRecord,"language") 
    ENDIF 
ENDIF

Set @BatchSMSList7 = LookupRows("Batch SMS List 7", "cust_id", cust_id) 

IF RowCount(@BatchSMSList7) > 0 THEN 

    Set @BatchSMSList7Record = Row(@BatchSMSList7,1) 
    Set @campaigncode = Field(@BatchSMSList7Record,"campaign_code") 
    set @message = Field(@BatchSMSList7Record, "message") 
    Set @BatchSMSMessage7 = LookupRows("Batch SMS Message 7", "campaign_code", @campaigncode, "message", @message) 
    Set @BatchSMSMessage7Record = Row(@BatchSMSMessage7,1) 

    IF @language == "ZH" THEN 
       Set @smsContent = Field(@BatchSMSMessage7Record,"sms_chi", @name, "cust_name") 
    ELSE 
       Set @smsContent = Field(@BatchSMSMessage7Record,"sms_eng", @name, "cust_name") 
    ENDIF

ENDIF 
]%%

%%=v(@smsContent)=%%

1 Answer 1

1

You've got some invalid syntax on the set @smsContent = Field() lines at the bottom. The field() function has three arguments, one optional.

It's a good practice wrap your personalization strings in the AttributeValue() function, to ensure null values are handled.

I'd also make heavy use of the output() function for debugging -- so you know what your variable values are when the AMPScript is executed.

You should also check for rowcount() after every lookup. You missed one after the Set @BatchSMSMessage7 = LookupRows() line.

%%[ 
VAR @language, @languages, @smsContent, @name, @custId, @names, @BatchSMSList7, @BatchSMSList7Record, @campaigncode, @message, @BatchSMSMessage7, @BatchSMSMessage7Record

set @custID = AttributeValue("cust_id")
set @name = AttributeValue("name")

output(concat("custID:",@custID))
output(concat(", name:",@name))

Set @names = LookupRows("SCV_SF", "cust_id", @custID)

output(concat(", RowCount(@names):",RowCount(@names)))

IF RowCount(@names) > 0 THEN 
  Set @nameRecord = Row(@names,1) 
  Set @name = Field(@nameRecord,"cust_name") 
  output(concat(", name:",@name))

ENDIF 

set @language = AttributeValue("language")

IF empty(@language) THEN

    Set @language = "EN" 
    Set @languages = LookupRows("SCV_SF", "cust_id", @custID)

    output(concat(", RowCount(@languages):",RowCount(@languages)))

    IF RowCount(@languages) > 0 THEN 
      Set @langRecord = Row(@languages,1) 
      Set @language = Field(@langRecord,"language") 
      output(concat(", language:",@language))
    ENDIF 

ENDIF

Set @BatchSMSList7 = LookupRows("Batch SMS List 7", "cust_id", @custID)

output(concat(", RowCount(@BatchSMSList7):",RowCount(@BatchSMSList7)))

IF RowCount(@BatchSMSList7) > 0 THEN 

    Set @BatchSMSList7Record = Row(@BatchSMSList7,1) 
    Set @campaigncode = Field(@BatchSMSList7Record,"campaign_code") 
    set @message = Field(@BatchSMSList7Record, "message") 

    output(concat(", campaigncode:",@campaigncode))  
    output(concat(", message:",@message))

    Set @BatchSMSMessage7 = LookupRows("Batch SMS Message 7", "campaign_code", @campaigncode, "message", @message) 

    output(concat(", RowCount(@BatchSMSMessage7):",RowCount(@BatchSMSMessage7)))

    if RowCount(@BatchSMSMessage7) > 0 THEN

        Set @BatchSMSMessage7Record = Row(@BatchSMSMessage7,1) 

        IF @language == "ZH" THEN 
           Set @smsContent = Field(@BatchSMSMessage7Record,"sms_chi")
        ELSE 
           Set @smsContent = Field(@BatchSMSMessage7Record,"sms_eng")
        ENDIF 

    endif 
ENDIF

]%%

%%=v(@smsContent)=%%
3
  • Hi Adam, Thank you so much for your kind walk-through. Had tried the above, however, SMS received as beneath:
    – Lindy Loo
    Commented Jun 26, 2017 at 11:29
  • custID: 123456789, name: Ms. Lindy Loo, Campaign Code: TestingBB, Message: 1. Wanted to fill the name into the DE (%%=v(@name)=%%) with different SMS contents, exp DE SMS Contents: Happy Birthday %%=v(@name)=%%! Kickstart your August Birthday staycation NOW!
    – Lindy Loo
    Commented Jun 26, 2017 at 11:30
  • I don't see any rowcount output. Commented Jun 26, 2017 at 12:01

You must log in to answer this question.

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