0

I am trying to pull blog info in one of our emails. the issue that I have is that I do not have a field that I can match on between the Sendable Data Extension & the non sendable data extension where I have the blog related data.

In the sendable data extension I have a destination field: example:

Rome, Lucca, Florence, Venice and Assisi

And in the blog piece I have a Location_City field data example: Rome|Florence

We agreed that if the first location from both of these data extension matches we will pull blog content otherwise will have a fallback content.

I had to add in the non sendable DE a default field of 1 as detailed here:

Exacttarget data extension - How to retrieve all rows in AMPScript

Below is my code:

%%[

SET @Location=AttributeValue('Product: Description')
SET @virgula=','


if IndexOf(@Location,@virgula) > 0 then 
  SET @PrimaryLocation=Substring(@Location,1, Subtract(IndexOf(@Location,@virgula),1))
  else SET @PrimaryLocation=@Location
endif 


SET @rows = LookupRows("Blog Post Reference Table","Default","1")
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 @Article = field(@row,"Article Title")
    set @Description = field(@row,"Description")
    set @Image = field(@row,"Image")
    SET @LinkTrip=field(@row,"Permalink")
    set @UrlFinal=RedirectTo(@LinkTrip)
    set @defaultURl='https://www.trafalgar.com'
    set @LocationCity=field(@row,"Location_City")
    set @bara='|'


  if IndexOf(@LocationCity,@bara) > 0 then 
  SET @LocationCity2=Substring(@LocationCity,1, Subtract(IndexOf(@LocationCity,@bara),1))
  else SET @LocationCity2=@LocationCity
endif 



if @PrimaryLocation==@LocationCity2 then
]%%

From the blog piece: <br>
Article name:%%=v(@Article)=%%

<br>

Description: %%=v(@Description)=%%
<br>
<a href="%%=RedirectTo(IIF(@nolink,v(@defaultURl),v(@UrlFinal)))=%%"><img src="%%=v(@Image)=%%"></a>

%%[else]%%
DEFAULT CONTENT

%%[endif]%%

%%[next @i ]%%



%%[ endif ]%%

Issue that I have is that for the rows where I don't have a match I get the default content; if I take out the else branch I don't have a default content.

I tried to rewrite using LookupOrderedRows but I couldn't get it working?

How should I re-write this in order to pull the default content piece when I do not have a match on the location?

Giuliettaenter image description here

2
  • I am sorry, I do not think I am understanding. You said you want a way for this to have a fallback, then said that your current code will display default if there is no match, then said you need us to help you resolve this so that when there is no match that default is displayed? Is there any way to clarify it a bit? Sorry if I am being dense, I just honestly don't understand the ask right now so not able to help... Commented Apr 23, 2020 at 12:59
  • 1
    Really sorry if I was not clear. The issue is in this piece of code: %%[else]%% DEFAULT CONTENT. As this is within the FOR loop for all the records in the non Sendable DE for which I do not have a match on location it will display the Default Content for each iteration of @i. When I get the match I get the correct blog content. If I take out this piece of code on the ELSE branch I get no default content when in a sendable DE I have no match on location in the blog DE. I hope this makes sense. I think i need to rewrite the Lookup on the Blog DE completely
    – Wallace
    Commented Apr 23, 2020 at 14:01

1 Answer 1

1

I believe doing the following to fake 'break' your loop if you get a match should do the trick.

%%[

SET @Location=AttributeValue('Product: Description')
SET @virgula=','

if IndexOf(@Location,@virgula) > 0 then 
  SET @PrimaryLocation=Substring(@Location,1, Subtract(IndexOf(@Location,@virgula),1))
  else SET @PrimaryLocation=@Location
endif 


SET @rows = LookupRows("Blog Post Reference Table","Default","1")
set @rowCount = rowcount(@rows)
if @rowCount > 0 then

  set @match = 0

  for @i = 1 to @rowCount do

    if @match == 0 then
      set @row = row(@rows, @i) /* get row based on counter */
      set @Article = field(@row,"Article Title")
      set @Description = field(@row,"Description")
      set @Image = field(@row,"Image")
      SET @LinkTrip=field(@row,"Permalink")
      set @UrlFinal=RedirectTo(@LinkTrip)
      set @defaultURl='https://www.trafalgar.com'
      set @LocationCity=field(@row,"Location_City")
      set @bara='|'


      if IndexOf(@LocationCity,@bara) > 0 then 
        SET @LocationCity2=Substring(@LocationCity,1, Subtract(IndexOf(@LocationCity,@bara),1))
      else 
        SET @LocationCity2=@LocationCity
      endif

      if @PrimaryLocation == @LocationCity2 then
        SET @match = 1
      endif

    endif 



    if @match then
]%%

From the blog piece: <br>
Article name:%%=v(@Article)=%%

<br>

Description: %%=v(@Description)=%%
<br>
<a href="%%=RedirectTo(IIF(@nolink,v(@defaultURl),v(@UrlFinal)))=%%"><img src="%%=v(@Image)=%%"></a>

%%[ else if @i == @rowcount then]%%
DEFAULT CONTENT

%%[
    endif
  next @i
endif 
]%%

The major change is that I added a variable called @match and had the setting of the variables for each iteration based on that value being 0 or false. Once a match is found, this value is changed to true, meaning that the loop continues, but takes no action.

In order to allow the default content to still display if there is no match, I enclosed your content output in a different AMPscript conditional. This will display based on the match variable. If the match variable is not met, then it goes to an else if statement. In this statement, we look to see if the iteration @i is equal to the final run of the loop @rowcount and if this is true, then displays the default content (as there were no matches) but otherwise nothing is output.

3
  • Did you just answer this meanwhile the Dev Talk for JourneyBuilder? Gortonington :D Commented Apr 23, 2020 at 14:28
  • I plead the fifth (American for I do not want to incriminate myself) Commented Apr 23, 2020 at 14:36
  • 1
    Thank you very much @Gortonington. That solved my issue. What I had to add was the break for the match==1 as it was pulling the same repetitive content when i had a match as this was now in the FOR loop :/. Adding the following in the code solved my issue: (....) if match==1 and i == rowCount then (..)
    – Wallace
    Commented Apr 24, 2020 at 8:06

You must log in to answer this question.

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