0

Below is current code, which works when pulling in variable content; however, I need a dynamic message to populate based on variables. The logic works but the variable content do not populate. Any help would be greatly appreciated!

%%[ 
SET @idSubscriber = MOBILE_NUMBER
SET @rows = LookupOrderedRows("SMS Data", 1, "MobileNumber", "MobileNumber", @idSubscriber) 
SET @RowCount = RowCount(@rows) 
    
IF (Rowcount(@rows) > 0) THEN 
        
    VAR @ILRow, @NursePhoneNumber, @HealthPortalTiny, @MobileHealth
    SET @ILRow = row(@rows,1) 
    SET @NursePhoneNumber = Field(@ILRow, "NursePhoneNumber") 
    SET @HealthPortalTiny = Field(@ILRow, "HealthPortalTiny") 
    SET @MobileHealth = Field(@ILRow, "MobileHealth") 

ENDIF 
]%%


%%[ 
Var @msg

IF (v(@HealthPortalTiny) == "NULL" OR v(@HealthPortalTiny) == "") THEN  
    SET @msg = "Health Msgs: You have a check-in call coming up! Be ready with any questions for your nurse. Call %%=v(@NursePhoneNumber)=%%. Txt STOPHEALTH to cancel."
ELSE
    SET @msg = "Health Msgs: You have a call coming up! Be ready with any questions for your nurse. Log in at: %%=v(@HealthPortalTiny)=%% or call %%=v(@NursePhoneNumber)=%%. Txt STOPHEALTH to cancel."
ENDIF
]%%  

%%=v(@msg)=%%
1
  • Did you ever get this working? Commented Oct 3, 2016 at 15:00

2 Answers 2

1

Simple solution:

  1. You do not need to wrap your conditional in parenthesis for AMPScript
  2. You do not need to use the V() function to declare the variable in your IF statement
  3. Use a CONCAT inside the setting of the @msg variable to add in the other variables you are looking to insert.
  4. Not necessary, but I find it solves a lot of issues/quirks - use TREATASCONTENT() function instead of V() to declare your variable in the message.

See below:

%%[    

SET @idSubscriber = MOBILE_NUMBER

SET @rows = LookupOrderedRows("SMS Data", 1, "MobileNumber", "MobileNumber", @idSubscriber)
SET @RowCount = RowCount(@rows)

IF Rowcount(@rows) > 0 THEN

VAR @ILRow, @NursePhoneNumber, @HealthPortalTiny, @MobileHealth

SET @ILRow = row(@rows,1)    
SET @NursePhoneNumber = Field(@ILRow, "NursePhoneNumber")           
SET @HealthPortalTiny = Field(@ILRow, "HealthPortalTiny")           
SET @MobileHealth = Field(@ILRow, "MobileHealth") 

ENDIF ]%%

%%[ Var @msg

IF @HealthPortalTiny == "NULL" OR @HealthPortalTiny == "" THEN

SET @msg = CONCAT("Health Msgs: You have a check-in call coming up! Be ready with any questions for your nurse. Call ", @NursePhoneNumber, ". Txt STOPHEALTH to cancel.")

ELSE

SET @msg = CONCAT("Health Msgs: You have a call coming up! Be ready with any questions for your nurse. Log in at: ", @HealthPortalTiny, " or call ", @NursePhoneNumber, ". Txt STOPHEALTH to cancel.")

ENDIF ]%%

%%=TreatAsContent(@msg)=%%
1

Adding to what @Gortonington mentioned, I'd code it a little more defensively, since your lookup could zero rows.

%%[ 

var @idSubscriber, @rowCount, @ILRow, @NursePhoneNumber, @HealthPortalTiny, @MobileHealth, @msg
SET @idSubscriber = MOBILE_NUMBER
SET @rows = LookupOrderedRows("SMS Data", 1, "MobileNumber", "MobileNumber", @idSubscriber) 
SET @RowCount = RowCount(@rows) 

set @HealthPortalTiny = ""
set @NursePhoneNumber = ""
set @MobileHealth = ""
   
IF (Rowcount(@rows) > 0) THEN 

    SET @ILRow = row(@rows,1) 
    SET @NursePhoneNumber = Field(@ILRow, "NursePhoneNumber") 
    SET @HealthPortalTiny = Field(@ILRow, "HealthPortalTiny") 
    SET @MobileHealth = Field(@ILRow, "MobileHealth") 

ENDIF 

IF not empty(@NursePhoneNumber) then

    IF empty(@HealthPortalTiny) THEN  
        SET @msg = concat("Health Msgs: You have a check-in call coming up! Be ready with any questions for your nurse. Call ", @NursePhoneNumber, ". Txt STOPHEALTH to cancel.")
    ELSE
        SET @msg = concat("Health Msgs: You have a call coming up! Be ready with any questions for your nurse. Log in at: ", @HealthPortalTiny, " or call ", @NursePhoneNumber, ". Txt STOPHEALTH to cancel."
    ENDIF

ELSE

  SET @msg = concat("Health Msgs: You have a check-in call coming up! Be ready with any questions for your nurse. Txt STOPHEALTH to cancel.")

ENDIF 
]%%  
%%=v(@msg)=%%

You must log in to answer this question.

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