I am trying to display 3 hotel contents in a for loop but I am getting the error while previewing only for specific contacts. Not able to solve this. Any help would be greatly appreciated.

This is my code.

``` SET @Rows = LookupRows('SWG_SR_HotelContent','version',@version,'LanguageCode',@LanguageCode)
FOR @Counter = 1 to 3 DO

                  SET @Row = Row(@Rows, @Counter)
                  SET @HotelName = Field(@Row,'HotelName')
                  SET @HotelCode = Field(@Row,'HotelCode')
                  SET @DestinationName = Field(@Row,'DestinationName')
                   SET @DestinationCountryName = Field(@Row,'DestinationCountryName')
                    SET @StarRating = Field(@Row,'StarRating')
                     SET @hotelDetail_collection = Field(@Row,'Collection')
                     SET @hotelDetail_concept = Field(@Row,'Concept')
                      SET @hotelDetail_hotelImages = Field(@Row,'HotelImages')
                       SET @HotelOverview = Field(@Row,'HotelOverview')
                       if IndexOf(@HotelOverview, "•") > 0 THEN
                       SET @HotelOverviewRemovebullets = replace(@HotelOverview,"•"," ")
                       ELSE IndexOf(@HotelOverview, "•") > 0 THEN
                       SET @HotelOverviewRemovebullets = replace(@HotelOverview,"•"," ")

VAR  @bullet1, @bullet2, @bullet, @rs

IF IndexOf(@HotelOverviewRemovebullets, "<br>") > 0 THEN
    SET @rs = BuildRowsetFromString(@HotelOverviewRemovebullets,'<br>')
    SET @bullet1 = Field(Row(@rs,1),1)
    SET @bullet2 = Field(Row(@rs,2),1)
     SET @bullet3 = Field(Row(@rs,3),1)

                        SET @HotelLink = Field(@Row,'HotelLink')
                         SET @HotelLink_CTA = CONCAT(@HotelLink,'?utm_source=mc-campaign&utm_medium=email&utm_campaign=swg_adhoc_search-retarget-journey-tf_20231218_en&utm_content=',@HotelCode,'-cta&utm_term=en&ajs_event=Email%20Link%20Clicked&ajs_uid=',SubscriberKey)
                         SET @HotelLink_IMG = CONCAT(@HotelLink,'?utm_source=mc-campaign&utm_medium=email&utm_campaign=swg_adhoc_search-retarget-journey-tf_20231218_en&utm_content=',@HotelCode,'-img&utm_term=en&ajs_event=Email%20Link%20Clicked&ajs_uid=',SubscriberKey)
                        /* Set the Collection JSON Array to a new variable to use to show badges */
  IF NOT EMPTY(@hotelDetail_collection) THEN
  SET @hotelDetail_collectionJson = @hotelDetail_collection

  /* Set the Concept JSON Array to a new variable to use to show badges */
  IF NOT EMPTY(@hotelDetail_concept) THEN
  SET @hotelDetail_conceptJson = @hotelDetail_concept

  IF NOT EMPTY(@hotelDetail_hotelImages) THEN
  VAR @hotelImages
  SET @hotelImages = BuildRowsetFromJSON(@hotelDetail_hotelImages, '$[:1]', 0)
  SET @rowcountimg = RowCount(@hotelImages)
  IF @rowcountimg > 0 THEN
  FOR @j = 1 TO RowCount(@hotelImages) DO
  SET @row = Row(@hotelImages, @j)
  SET @Image = Field(@row,1)
  NEXT @j
                        ]%% ```


1 Answer 1


It looks like your LookupRows returns less than 3 rows. You should check if Rowcount(@Rows) is less than 3. And in that case limit the loop to the result of RowCount - otherwise 3.

  • ^What Lukas said, also the variable name "row" is used twice (uppercase and lowercase). AMPscript is case insensitive so that conflict might also be part of the problem. Commented Mar 15 at 21:57
  • Initially i put the loop to rowcount but that was also erroring so that’s why I changed it to 3 and there are 3 rows for every destination. The lookup table has 3 hotels exactly for each destination in there. For most of the destinations the email content is being correctly pulled in but selectively few destinations are erroring. Going real crazy here lol. Tried the case sensitive thing too but nothing works. Commented Mar 16 at 22:21
  • Have you been able to identify what is different between the ones that work, and ones that don't? I think some "error catches" added to your code will help identify what the difference is. Also, would you be open to posting the HTML that you're expecting to display? It would help (at least me) have a better idea of what you're trying to accomplish. It would also help in ensuring that the @Counter loop is closed in the right spot. Commented Mar 17 at 1:52
  • I fixed it. I was looking for an issue in the main lookup table. But there is another array index within a column and there it was. Thanks. Commented Mar 17 at 18:50

You must log in to answer this question.

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