2

For some reason I'm having trouble looping through records in my sample DE. I have three records being stored in the DE and I'm trying to loop the HTML Table three times to print all of the fields from the data extension.

My AMPscript passes validation but errors when I generate a preview send. My error message and AMPscript are posted below. Any help is much appreciated. Thanks everybody.

Error Message: enter image description here

AMPscript Code:

%%[
  var @nmaratasDE, @rsRow, @i, @email_address, @first_name, @last_name, @address, @city, @state, @zip, @language
  SET @nmaratasDE = LookupRows("nmaratasDE")

  IF RowCount(@nmaratasDE) > 0 THEN
    FOR @i = 1 to RowCount(@nmaratasDE) DO
      SET @rsRow = Field(Row(@nmaratasDE, @i))
      SET @email_address = Field(@rsRow, "email_address")
      SET @first_name = Field(@rsRow, "first_name")
      SET @last_name = Field(@rsRow, "last_name")
      SET @address = Field(@rsRow, "address")
      SET @city = Field(@rsRow, "city")
      SET @state = Field(@rsRow, "state")
      SET @zip = Field(@rsRow, "zip")
      SET @language = Field(@rsRow, "language")
      ]%%
      <table width="650" border="0" cellspacing="0" cellpadding="0" style="width:100%; max-width:650px; padding:10px; display:block; border:1px dashed red;">
        <tr>
          <td>
            <strong>Email Address: </strong> %%=v(@email_address)=%%<br>
            <strong>First Name: </strong> %%=v(@first_name)=%%<br>
            <strong>Last Name: </strong> %%=v(@last_name)=%%<br>
            <strong>Address: </strong> %%=v(@address)=%%<br>
            <strong>City: </strong> %%=v(@city)=%%<br>
            <strong>State: </strong> %%=v(@state)=%%<br>
            <strong>Zip: </strong> %%=v(@zip)=%%<br>
            <strong>Language: </strong> %%=v(@language)=%%
          </td>
        </tr>
      </table>
      %%[
      NEXT  @i
  ENDIF
]%%
1

You're missing some fields in your lookupRows() function. You'll need to specify some sort of lookup field and a matching value. Sometimes I'll add a lookupKey column to DE and set a default value to "1" and then use that as my lookup value.

 %%[
      var @nmaratasDE, @rsRow, @i, @email_address, @first_name, @last_name, @address, @city, @state, @zip, @language

      var @lookupValue
      set @lookupValue = "whee"

      set @nmaratasDE = LookupRows("nmaratasDE","LookupColumn", @lookupValue)

      IF RowCount(@nmaratasDE) > 0 THEN
        FOR @i = 1 to RowCount(@nmaratasDE) DO
          SET @rsRow = Row(@nmaratasDE, @i)
          SET @email_address = Field(@rsRow, "email_address")
          SET @first_name = Field(@rsRow, "first_name")
          SET @last_name = Field(@rsRow, "last_name")
          SET @address = Field(@rsRow, "address")
          SET @city = Field(@rsRow, "city")
          SET @state = Field(@rsRow, "state")
          SET @zip = Field(@rsRow, "zip")
          SET @language = Field(@rsRow, "language")
          ]%%
          <table width="650" border="0" cellspacing="0" cellpadding="0" style="width:100%; max-width:650px; padding:10px; display:block; border:1px dashed red;">
            <tr>
              <td>
                <strong>Email Address: </strong> %%=v(@email_address)=%%<br>
                <strong>First Name: </strong> %%=v(@first_name)=%%<br>
                <strong>Last Name: </strong> %%=v(@last_name)=%%<br>
                <strong>Address: </strong> %%=v(@address)=%%<br>
                <strong>City: </strong> %%=v(@city)=%%<br>
                <strong>State: </strong> %%=v(@state)=%%<br>
                <strong>Zip: </strong> %%=v(@zip)=%%<br>
                <strong>Language: </strong> %%=v(@language)=%%
              </td>
            </tr>
          </table>
          %%[
          NEXT  @i
      ENDIF
    ]%%

Also, there are a lot more people answering SFMC questions over at salesforce.stackexchange.com -- mostly tagged with marketing-cloud, ampscript, and soap-api.

  • Hey thanks for your help Adam. I didn't realize my LookupRows was written incorrectly. I went ahead and made those AMPscript changes and added an additional column to my DE called lookup_key and assigned a default text value of 1 to each of my records. But for some reason when I generate preview I keep getting the same error. It's really strange... – Nolan Feb 24 '15 at 16:44
  • I see the issue -- SET @rsRow = Field(Row(@nmaratasDE, @i)) should be SET @rsRow = Row(@nmaratasDE, @i). I updated my answer. – Adam Spriggs Feb 24 '15 at 16:49
  • Thanks for commenting back so fast. Alright I just tried that also and still no dice. This is the weirdest thing ever, I've never had so much trouble writing a for loop before lol. – Nolan Feb 24 '15 at 17:00
  • I'd take out all of the fields but one and add them back one at a time. – Adam Spriggs Feb 24 '15 at 17:31
  • 1
    ahh that's a good idea I'm going to give that a shot and see what happens. Hey thanks for all your help man I really appreciate it :) – Nolan Feb 24 '15 at 17:46
0

Question Answer

With the help of a colleague I was able to figure this out. The answer is below. Thank you to everyone that helped.

%%[
    var @lookupValue
    var @nmaratasDE
    var @i
    var @rowCount

    set @lookupValue = "1"
    set @nmaratasDE = lookupRows("nmaratasDE","lookup_key", @lookupValue)
    for @i = 1 to rowCount(@nmaratasDE) do
      set @rowCount = row(@nmaratasDE,@i)
      ]%%
      <table width="650" border="0" cellspacing="0" cellpadding="0" style="width:100%; max-width:650px; padding:10px; display:block; border:1px dashed red;">
        <tr>
          <td>
            <strong>Email Address: </strong> %%=field(@rowCount,"email_address")=%%<br>
            <strong>First Name: </strong> %%=field(@rowCount,"first_name")=%%<br>
            <strong>Last Name: </strong> %%=field(@rowCount,"last_name")=%%<br>
            <strong>Address: </strong> %%=field(@rowCount,"address")=%%<br>
            <strong>City: </strong> %%=field(@rowCount,"city")=%%<br>
            <strong>State: </strong> %%=field(@rowCount,"state")=%%<br>
            <strong>Zip: </strong> %%=field(@rowCount,"zip")=%%<br>
            <strong>Language: </strong> %%=field(@rowCount,"language")=%%
          </td>
        </tr>
      </table>
      %%[
      next @i
]%%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.