0

I am using the LookupOrderedRows function to pull apartment suggestions into an email, but when there are no apartments available in the lookup DE it displays nothing.

I would like to know if there is a way I can identify when there are 0 results returned so that I can display backup content instead.

Is this possible? If so, how?

Here is a shortened version of the code:

    %%[
    var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i,
    
    set @lookupValue = AttributeValue("Opportunity:City__c") 
    set @lookupValue2 = '1' 
    set @MonthlyRent__c = AttributeValue("Opportunity:Monthly_rent__c")
    set @numRowsToReturn = 3 
    set @rows = LookupOrderedRows("Filter_Available_Apartments_1100_1200",@numRowsToReturn,"Price__c, Code__c, Street__c, Postal_Code__c, CurrencyIsoCode, Country_Code__c, Homelike_ID__c, Cover_picture__c, Number_of_allowed_residents__c, Number_of_bedrooms__c, Number_of_bathrooms__c, Enabled_Booking_Modes__c, Cancellation_Flexibility__c, Security_Deposit__c, Available_From__c,","City__c", @lookupValue,"Number_of_bedrooms__c",@lookupValue2)
    set @rowCount = rowcount(@rows)
    
    if @rowCount > 0 then
    
      for @i = 1 to @rowCount do
    
        set @row = row(@rows,@i) /* get row based on counter */
        set @Code__c = field(@row,"Code__c")
        set @Street__c = field(@row,"Street__c") 
    
        ]%%
    <div class="apartment">
      <table>
      </table>
    </div><br>%%[next @i]%%%%[ENDIF]%%

1 Answer 1

4

You are actually already checking that… in this line:

if @rowCount > 0 then

You need to replace your last ENDIF with ELSE, in order to display your fallback content, as shown here below:

</div><br>%%[next @i]%%
%%[ELSE]%%
Fallback content
%%[ENDIF]%%
1
  • Aaha! Great! Thank you @lukas. I wasn't sure where the ELSE statement had to go, so thank you for pointing it out. Commented Jan 9, 2023 at 18:15

You must log in to answer this question.

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