0

Given that I have already declared my variables... I am trying to set some values to those variables, based on whether a row of data already exists or not...

 VAR @brandID, @Content, @Header, @subscriberkey, @cottage1ID, @cottage2ID, @cottage1Name, @cottage2Name, @viewDate1, @viewedProperties, @viewedPropertyRow, @viewedPropertiesRows, @viewPropertyCount, @viewDate2, @currentDate, @dayDiff,  @bookingRows, @AllBookingRow1, @bookingRowCount, @AllBookingRowCount1, @viewedPropertyID, @AllBookingRow2, @AllBookingRowCount2, @viewedOtherPropertiesRows, @viewedOtherPropertyRow, @viewedOtherProperties, @viewOtherPropertyCount

Could someone explain to me, why this works:

 SET @viewedPropertiesRows = LookupRows("Viewed Properties","Subscriber Key", @subscriberkey, "brandID", @brandID)
 SET @viewPropertyCount = rowcount(@viewedPropertiesRows)
   IF @viewPropertyCount > 0 THEN
    SET @viewedPropertyRow = row(@viewedPropertiesRows, 1)
    SET @cottage1Name = field(@viewedPropertyRow,"cottage1Name")
    SET @cottage2Name = field(@viewedPropertyRow,"cottage2Name")
    SET @cottage1ID =  field(@viewedPropertyRow,"cottage1PropertyID")
    SET @cottage2ID =  field(@viewedPropertyRow,"cottage2PropertyID")
    SET @viewDate1 = FormatDate(field(@viewedPropertyRow,"View1_happenedAt"), 'yyyy-MM-DD')
    SET @dayDiff = DateDiff(@viewDate1,@currentDate,"D")
   ENDIF
  
 IF(EMPTY(@viewPropertyCount) OR @viewPropertyCount == 0) THEN

    SET @viewedOtherPropertiesRows = LookupRows("Viewed Properties","Subscriber Key", @subscriberkey, "brandID", 1)
    SET @viewOtherPropertyCount = rowcount(@viewedOtherPropertiesRows)
    IF @viewOtherPropertyCount > 0 THEN
        SET @viewedOtherPropertyRow = row(@viewedOtherPropertiesRows, 1)
        SET @cottage1NameOther = field(@viewedOtherPropertyRow,"cottage1Name")
        SET @cottage2NameOther = field(@viewedOtherPropertyRow,"cottage2Name")
        SET @cottage1IDOther =  field(@viewedOtherPropertyRow,"cottage1PropertyID")
        SET @cottage2IDOther =  field(@viewedOtherPropertyRow,"cottage2PropertyID")
        SET @viewDate1Other = FormatDate(field(@viewedOtherPropertyRow,"View1_happenedAt"), 'yyyy-MM-DD')
        SET @dayDiffOther = DateDiff(@viewDate1Other,@currentDate,"D")
    ENDIF

  ENDIF

but this doesn't:

    SET @viewedPropertiesRows = LookupRows("Viewed Properties","Subscriber Key", @subscriberkey, "brandID", @brandID)
    SET @viewPropertyCount = rowcount(@viewedPropertiesRows)
    IF @viewPropertyCount > 0 THEN
        SET @viewedPropertyRow = row(@viewedPropertiesRows, 1)
        SET @cottage1Name = field(@viewedPropertyRow,"cottage1Name")
        SET @cottage2Name = field(@viewedPropertyRow,"cottage2Name")
        SET @cottage1ID =  field(@viewedPropertyRow,"cottage1PropertyID")
        SET @cottage2ID =  field(@viewedPropertyRow,"cottage2PropertyID")
        SET @viewDate1 = FormatDate(field(@viewedPropertyRow,"View1_happenedAt"), 'yyyy-MM-DD')
        SET @dayDiff = DateDiff(@viewDate1,@currentDate,"D")

    ELSEIF(EMPTY(@viewPropertyCount) OR @viewPropertyCount == 0) THEN

        SET @viewedOtherPropertiesRows = LookupRows("Viewed Properties","Subscriber Key", @subscriberkey, "brandID", 1)
        SET @viewPropertyCount = rowcount(@viewedPropertiesRows)
        IF @viewPropertyCount > 0 THEN
            SET @viewedPropertyRow = row(@viewedPropertiesRows, 1)
            SET @cottage1Name = field(@viewedPropertyRow,"cottage1Name")
            SET @cottage2Name = field(@viewedPropertyRow,"cottage2Name")
            SET @cottage1ID =  field(@viewedPropertyRow,"cottage1PropertyID")
            SET @cottage2ID =  field(@viewedPropertyRow,"cottage2PropertyID")
            SET @viewDate1 = FormatDate(field(@viewedPropertyRow,"View1_happenedAt"), 'yyyy-MM-DD')
            SET @dayDiff = DateDiff(@viewDate1,@currentDate,"D")
        ENDIF
        
    ENDIF

I feel like I am going crazy, but there must be a rational reason! many thanks

1 Answer 1

0

You're mixing your other variables.

In the second example, in the ELSEIF section,

the SET @viewPropertyCount = rowcount(@viewedPropertiesRows)

should be: SET @viewPropertyCount = rowcount(@viewedOtherPropertiesRows)

and the: SET @viewedPropertyRow = row(@viewedPropertiesRows, 1)

should be: SET @viewedPropertyRow = row(@viewedOtherPropertiesRows, 1)

I'd probably write it something like this:

%%[

set @debug = 1

SET @viewedPropertiesRows = LookupRows("Viewed Properties","Subscriber Key", @subscriberkey, "brandID", @brandID)
SET @viewPropertyCount1 = rowcount(@viewedPropertiesRows)

IF @viewPropertyCount1 > 0 THEN

    SET @viewedPropertyRow = row(@viewedPropertiesRows, 1)
    SET @cottage1Name = field(@viewedPropertyRow,"cottage1Name")
    SET @cottage2Name = field(@viewedPropertyRow,"cottage2Name")
    SET @cottage1ID =  field(@viewedPropertyRow,"cottage1PropertyID")
    SET @cottage2ID =  field(@viewedPropertyRow,"cottage2PropertyID")
    SET @viewDate1 = FormatDate(field(@viewedPropertyRow,"View1_happenedAt"), 'yyyy-MM-DD')
    SET @dayDiff = DateDiff(@viewDate1,@currentDate,"D")

ELSE

    set @brand = 1
    SET @viewedPropertiesRows = LookupRows("Viewed Properties","Subscriber Key", @subscriberkey, "brandID", @brand)
    SET @viewPropertyCount2 = rowcount(@viewedPropertiesRows)

    IF @viewPropertyCount2 > 0 THEN

        SET @viewedPropertyRow = row(@viewedPropertiesRows, 1)
        SET @cottage1Name = field(@viewedPropertyRow,"cottage1Name")
        SET @cottage2Name = field(@viewedPropertyRow,"cottage2Name")
        SET @cottage1ID =  field(@viewedPropertyRow,"cottage1PropertyID")
        SET @cottage2ID =  field(@viewedPropertyRow,"cottage2PropertyID")
        SET @viewDate1 = FormatDate(field(@viewedPropertyRow,"View1_happenedAt"), 'yyyy-MM-DD')
        SET @dayDiff = DateDiff(@viewDate1,@currentDate,"D")

    ELSE

        raiseError("no properties found", 1)

    ENDIF


ENDIF

if @debug == 1 then

    output(concat("<br>brandID: ", @brandID))
    output(concat("<br>viewPropertyCount1: ", @viewPropertyCount1))
    output(concat("<br>viewPropertyCount2: ", @viewPropertyCount2))
    output(concat("<br>cottage1Name: ", @cottage1Name))
    output(concat("<br>cottage2Name: ", @cottage2Name))
    output(concat("<br>cottage1ID: ", @cottage1ID))
    output(concat("<br>cottage2ID: ", @cottage2ID))
    output(concat("<br>viewDate1: ", @viewDate1))
    output(concat("<br>dayDiff: ", @dayDiff))
    output(concat("<br>currentDate: ", @currentDate))

endif 

]%%
5
  • Ah yes you're right - good spot, thanks Adam. I've re-written it 5 or 6 times and can't think that I missed that each time but your solution seems nicer, will give it a go and report back!
    – Tim
    Commented Jun 19 at 13:37
  • v strange, some variables output, but for some reason cottage1Name is still null, despite having a value in the lookup DE, there's no char limit or anything is there? (field length is set to 100 chars)
    – Tim
    Commented Jun 19 at 15:02
  • No character limits, no. But perhaps leading or trailing spaces in the DE field name. Commented Jun 19 at 17:11
  • Updated my example above to include a method you might try for debugging. Just toggle the @debug variable to 0 when you're satisfied with how it's functioning. Commented Jun 19 at 17:17
  • 1
    can't thank you enough for your help Adam.... The debugging really helped... turns out the contentBlock I was pulling in was overwriting the values, logging them out helped me find a solution!
    – Tim
    Commented Jun 21 at 9:39

You must log in to answer this question.

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