Skip to main content
added 2 characters in body
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

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

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

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

Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

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)=%%