1

I have a data extension named "MemberList" and I am attempting to create an email to apply members who are missing items to become full members. Some are missing one item, some four to five items. I need to have all the missing items go into a list in an email and am struggling with getting the items grouped by "memberId" and using a for loop, putting the items into one email. Here is the code I am working with:

%%[

/* setting the variables and looking up columns and data within the Data Extension*/

Var @firstName, @lastName, @email, @location, @itemCode,@itemDescription,@memberId,@rows,@row,@rowCount

Set @firstName = FirstName
Set @lastName = LastName
Set @email = EmailAddress
Set @location = Location
Set @itemCode = ItemCode
Set @itemDescription = ItemDescription
Set @memberId = MemberID

Set @rows = Lookup("MemberList", "MemberID", @memberId)
Set @rowCount = rowcount(@rows)

if @rowCount > 0 then

/*for loop*/

for @i = 1 to rowCount(@rows) do

  Set @row= ROW(@rows, @i)

]%%
<tr>
    <td>%%=Field(@row, @location)=%%</td>
    <td>%%=Field(@row, @itemCode)=%%</td>
</tr>

%%[
next @i
]%%

Error I am receiving when doing a send preview in Marketing Cloud is:

Invalid column name (parameter 2) passed to Field function. No column of the specified name was found. Invalid Field Name: WA Function: Field(@row, Location)

1

There are a couple of issues here. The error indicates that you don't have a field named 'Location' in the context of the Sendable Data Extension that you are using to send the email. I assume you are using a different DE to send from (i.e. you are not using 'MemberList' DE).

Also, you should be using LookupRows() instead of Lookup(). The following code will work.

<!DOCTYPE html>
<html>
<head>
<style>

table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 400px;
}

td, th {
    font-family: arial, sans-serif;
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
</style>
</head>
<body>
<table>
  <tr>
    <th>Location</th>
    <th>Item Code</th>
  </tr>

%%[

var @firstName, @lastName, @email,
var @itemDescription, @memberId, @rows, @row, @rowCount

Set @memberId = AttributeValue('MemberID')
Set @rows = LookupRows("MemberList", "MemberID", @memberId)
Set @rowCount = rowcount(@rows)

if @rowCount > 0 then

var @i
for @i = 1 to @rowcount do
set @row = Row(@rows,@i) 

]%%

   <tr>
      <td>%%=Field(@row, "Location")=%%</td>                                                                                          
      <td>%%=Field(@row, "ItemCode")=%%</td>
   </tr>

%%[ next @i ]%%

%%[ else ]%%

 <tr><td colspan="2" >No records found.</td></tr>

%%[ endif ]%% 

</table>

</body>
</html>
  • MembersList is the same data extension that I am referencing and sending from. That can't be done? – kidaiu Apr 13 '17 at 13:28
  • Yes it can be done and my code should work for that scenario too. I was just referring to the error message that you we're seeing, which is typically returned when the field does not exist. – Eliot Harper Apr 13 '17 at 18:31
  • Be aware that if you have duplicate MemberID values in your Sendable DE (which it appears you do), then you will want to de-duplicate by email address at time of sending, otherwise the members will receive multiple emails (one for each row where they appear). The preferred solution would be to create a separate DE containing a single MemberID field and write a query to populate that DE from your MemberList DE, something like: SELECT DISTINCT [MemberID] FROM [MemberList] — then use this new DE as your Sendable DE. – Eliot Harper Apr 17 '17 at 1:33

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.