0

I have an ELSEIF AMPscript statement that looks like this:

<script runat=server language=ampscript>

var @code, @templateName

set @code = 'M200'

if @code == 'E001' then
   set @templateName = 'Letter A'
elseif @code == 'M001'
     or @code == 'M014'
     or @code == 'M400' then
   set @templateName = 'Letter B'
elseif @code == 'M002'
     or @code == 'M500' then
   set @templateName = 'Letter C'
elseif @code == 'M003' 
     or @code == 'M200' then
   set @templateName = 'Letter D'
elseif  @code == 'M004'
     or @code == 'M005'
     or @code == 'M006'
     or @code == 'M007'
     or @code == 'M008'
     or @code == 'M009'
     or @code == 'M010'
     or @code == 'M011'
     or @code == 'M012'
     or @code == 'M013'
     or @code == 'M600' then
    set @templateName = 'Letter E'
elseif @code == 'M015' then
   set @templateName = 'Letter F'
elseif @code == 'V100' then
   set @templateName ='Letter G'
else
   set @templateName = 'undefined'
endif
</script>

%%=v(@templateName)=%%

I would expect @templateName to return 'Letter D' but it is returning 'Letter E'. Why do you think this is?

3
  • I can't reproduce this behavior. Is it in an email? Oct 24, 2016 at 15:08
  • My first thought was it block definition -- <script runat=server language=ampscript><script> -- since it is processed differently than the traditional %%[ ]%% . That's the way I understand it. Oct 24, 2016 at 15:13
  • @AdamSpriggs if you copy and paste the example above into an email you will be able to reproduce. However you are correct; if I use %%[ ]%% in my email, then it works. I thought the tag based syntax could be used interchangeably — I had no idea that they are evaluated differently! Oct 24, 2016 at 20:18

1 Answer 1

4

I figured it out. I used two space characters after one of my elseif statements for formatting (alignment) purposes:

elseif  @code == 'M004'

If you do this, it appears that the if statement evaluation breaks and returns the incorrect result. As soon as I remove the second space character, it works correctly:

elseif @code == 'M004'
1
  • Thank you! This was driving me crazy and this solution not something I had even considered as being able to cause the error.
    – c4collins
    Mar 8, 2017 at 19:28

You must log in to answer this question.

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