0

If I do the following

set @currentOutlet= 1
set @previousOutlet= 0
if @email_rowCount != 0 then
  for @i = 1 to @email_rowCount do
    set @this_row = row(@email_rows,@i) /*get row based on loop counter */
    set @currentOutlet= field(@this_row,"OutletNumber")
    set @OutletName = field(@this_row,"OutletName")
    output(concat("before if c:", v(@currentOutlet), "p:", v(@previousOutlet)))
    if @currentOutlet != @previousOutlet then
      output(concat("c:", v(@currentOutlet), "p:", v(@previousOutlet)))
      /* stuff I want to do if not equal deleted from here for clarity */
    endif
    set @previousOutlet = @currentOutlet
  next @i
endif

I get:

before if c:12345p:0
c:12345p:0
before if c:12345p:12345
c:12345p:12345

I would have expected to only see this on output:

before if c:12345p:0
c:12345p:0
before if c:12345p:12345

@email_rows has 2 rows, @email_rowcount is 2, the outletNumber is the same on both rows based on visual inspection and the output statements

So despite current being the same as previous, the content in the if is being printed. Is there something weird about variables that I need to use to allow inequality to be testing the value, is it some string matching weirdness?

1 Answer 1

0

Updated final answer, everything works like it should:

<br>
Group1
<br>

%%[
var @current, @previous
set @current = 0
set @previous = 1
set @fieldvalue = "1"

set @rows = LookupRows("UNEQUAL_TEST","GROUP", @fieldvalue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    for @i = 1 to @rowcount do
        set @row = row(@rows,@i)
        set @current = field(@row, "email")
        output(concat("Start Iteration:",@i,"<br>"))
        output(concat('BEFORE IF current:', v(@current), '; previous:', v(@previous),"<br>"))
        if @current != @previous then
            output(concat('NOT EQUAL current:', v(@current), '; previous:', v(@previous),"<br>"))
        endif
        set @previous = @current
        output(concat("End Iteration:",@i,"<br><br>"))
    next @i
endif

]%%

<br>
Group2
<br>

%%[
var @current, @previous
set @current = 0
set @previous = 1
set @fieldvalue = "2"

set @rows = LookupRows("UNEQUAL_TEST","GROUP", @fieldvalue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    for @i = 1 to @rowcount do
        set @row = row(@rows,@i)
        set @current = field(@row, "email")
        output(concat("Start Iteration:",@i,"<br>"))
        output(concat('BEFORE IF current:', v(@current), '; previous:', v(@previous),"<br>"))
        if @current != @previous then
            output(concat('NOT EQUAL current:', v(@current), '; previous:', v(@previous),"<br>"))
        endif
        set @previous = @current
        output(concat("End Iteration:",@i,"<br><br>"))
    next @i
endif

]%%

<br>
Group3
<br>

%%[
var @current, @previous
set @current = 0
set @previous = 1
set @fieldvalue = "3"

set @rows = LookupRows("UNEQUAL_TEST","GROUP", @fieldvalue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    for @i = 1 to @rowcount do
        set @row = row(@rows,@i)
        set @current = field(@row, "email")
        output(concat("Start Iteration:",@i,"<br>"))
        output(concat('BEFORE IF current:', v(@current), '; previous:', v(@previous),"<br>"))
        if @current != @previous then
            output(concat('NOT EQUAL current:', v(@current), '; previous:', v(@previous),"<br>"))
        endif
        set @previous = @current
        output(concat("End Iteration:",@i,"<br><br>"))
    next @i
endif

]%%

DataExtension UNEQUAL_TEST:

Dataextension Unequal test

Output:

Group1 
Start Iteration:1
BEFORE IF current:[email protected]; previous:1
NOT EQUAL current:[email protected]; previous:1
End Iteration:1

Start Iteration:2
BEFORE IF current:[email protected]; previous:[email protected]
End Iteration:2

Start Iteration:3
BEFORE IF current:[email protected]; previous:[email protected]
End Iteration:3


Group2 
Start Iteration:1
BEFORE IF current:[email protected]; previous:1
NOT EQUAL current:[email protected]; previous:1
End Iteration:1

Start Iteration:2
BEFORE IF current:[email protected]; previous:[email protected]
End Iteration:2

Start Iteration:3
BEFORE IF current:[email protected]; previous:[email protected]
NOT EQUAL current:[email protected]; previous:[email protected]
End Iteration:3


Group3 
Start Iteration:1
BEFORE IF current:[email protected]; previous:1
NOT EQUAL current:[email protected]; previous:1
End Iteration:1

Start Iteration:2
BEFORE IF current:[email protected]; previous:[email protected]
NOT EQUAL current:[email protected]; previous:[email protected]
End Iteration:2

Start Iteration:3
BEFORE IF current:[email protected]; previous:[email protected]
NOT EQUAL current:[email protected]; previous:[email protected]
End Iteration:3

end of final answer.



First answer:

Your code has some bad brackets. For example every output line needs to have two additional closing brackets.

My Script:

%%[
var @current, @previous
set @current = 0
set @previous = 1
set @fieldvalue = 999999

set @rows = LookupRows("DataExtension_Name","fieldname", @fieldvalue)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then
    for @i = 1 to @rowcount do
        set @row = row(@rows,@i)
        set @current = field(@row, "otherOrSameFieldname")
        if @current == @previous then
            output(concat('EQUAL c:', v(@current), 'p:', v(@previous),"<br>"))
        elseif @current != @previous then
            output(concat('NOT EQUAL c:', v(@current), 'p:', v(@previous),"<br>"))
        endif
        set @previous = @current
    next @i
endif

]%%

Output when all values of "otherOrSameField" would be the same (12345) and you get 4 rows with your LookUpRows function:

NOT EQUAL c:12345p:1
EQUAL c:12345p:12345
EQUAL c:12345p:12345
EQUAL c:12345p:12345

This is like you want it to be.

Output when all values "otherOrSameField" are different and you get 4 rows with your LookUpRows function:

NOT EQUAL c:12345p:1
NOT EQUAL c:23456p:12345
NOT EQUAL c:34567p:23456
NOT EQUAL c:45678p:34567

This is also the way you want it to be. I do not understand what you think does not work.

6
  • I don't understand you code, specifically why your if statement requires a test of if A elseif not A. Surely the else part of an if statement is the not of the original boolean expression.
    – harry
    Commented Feb 18, 2019 at 20:14
  • I wrote it for understanding purposes. Of course I could have changed it to else but people tend to understand conditions better (from my experience). What would you like to have explained which you didnt understand? Commented Feb 18, 2019 at 20:24
  • Thanks for all your help. Your code is very similar to what I have, however as explained in the original post. Prior to the if statement previous and current are the same, as evidenced in the "before" output, hence the next output should not come out, since the if statement should only work if they are unequal. But the output comes out printing equal values for previous and current.
    – harry
    Commented Feb 18, 2019 at 20:36
  • It is not. You did not share how you set @this_row. We dont know if there is any loop that sets it or is it a static variable? You did not share how your data looks and you didnt share how many rows you get back. Neither we know how your output was generated. How many iterations have been done 1 or 2? I gave you an existing working code that i tested which shows that its working like designed. Commented Feb 18, 2019 at 20:42
  • I understand your frustration Johannes. I haven't been precise enough. I've gotten the actual code and pasted it above (rather than my previous simplification). I looks very similar to yours, yet the loop executes the body twice, though I expected it to loop twice but not execute the body the second time because the value in currentOutlet should be the same as previousOutlet because both rows in email_rows should have the same value in the OutletNumber field.
    – harry
    Commented Feb 18, 2019 at 22:35

You must log in to answer this question.

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