0

I have an issue to understand the else if statement, so basically if city is empty I want it to show: no rows found, I tried to add: %%[ if @rowCount > 1, from my understanding if there's city, then it shows the list, but if it's 0, it would show: No rows found

However, instead of showing: No rows found, it's still showing the person list eventhough the city is empty.

My question, when city is blank or there's no city, how to replace it with: No rows found?

%%[


set @city = AttributeValue("MailingCity")
set @rows = LookupRows("TEST DE","TestCity", @city)

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 @Name = field(@row,"FirstName")
    set @TestCity = field(@row,"TestCity")

    ]%%

    %%=v(@i)=%%

    %%=v(@Name)=%%
    %%=v(@TestCity)=%%

%%[ next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%
2
  • Not sure if copy/paste error but you are missing the %% in front of the [ before your next statement. E.g. [ next @i ]%% should be %%[ next @i ]%% Jun 21, 2022 at 17:44
  • Yes it's just copy paste error, I didn't go detail on the structure, but my question, what do I need to do if I want to show: No rows found when city is empty on the list?
    – Uss
    Jun 21, 2022 at 17:52

1 Answer 1

0

So I think the issue you are running into is that you have null values in your TestCity field in the TEST DE data extension. This means that when you do the lookupRows to a null value (e.g. MailingCity is empty/null) then it returns those rows that have null from your DE.

This is likely why you are getting a false positive result and it is returning a rowcount. Something like the below should remove this issue.

%%[

set @city = AttributeValue("MailingCity")

IF NOT EMPTY(@city) THEN
  set @rows = LookupRows("TEST DE","TestCity", @city)
  set @rowCount = rowcount(@rows)
ELSE
  set @rowCount = 0
ENDIF

]%%

%%[ if @rowCount > 0 then

for @i = 1 to @rowCount do

    set @row = row(@rows, @i) /* get row based on counter */
    set @Name = field(@row,"FirstName")
    set @TestCity = field(@row,"TestCity")

    ]%%

    %%=v(@i)=%%

    %%=v(@Name)=%%
    %%=v(@TestCity)=%%

%%[ next @i ]%%

%%[ else ]%%

No rows found

%%[ endif ]%%
1
  • Thanks a lot, this is working
    – Uss
    Jun 21, 2022 at 18:50

You must log in to answer this question.

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