0

I have built my ampscript code for one to many relationship but every time i am only getting first row for my lookup data extension as i have one customer id in my first data extension and based on this id i have 3 products records related to this customers id, So i try to populate all 3 records from lookup data extension i am getting only first row repeated record. Please review my below code

<!DOCTYPE html>
<html>
<head>
<style>
table {
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
}
</style>
</head>
<body>

<h2>Wish List Items</h2>

<table>

  <tr>
<th>Product Name</th>
    <th>Product Code</th>
    <th>Product Quantity</th>
  </tr>
   <tr>
%%[

var @ids,@count,@prodctid,@acount
set @ids = AttributeValue("Id")
set @acount = RowCount(LookupRows('WishList__c','Id',@ids))
set @count = RowCount(LookupRows('Wish_List_Item__c','Wish_List__c',@ids))

FOR @i = 1 to @acount DO ]%%

%%[FOR @j = 1 to @count DO

   set @prodctid = Lookup("Wish_List_Item__c","Id","Wish_List__c",@ids)


]%%

<td>%%=Lookup("Wish_List_Item__c","Name","Id",@prodctid)=%%</td>
    <td>%%=Lookup("Wish_List_Item__c","Product_Code__c","Id",@prodctid)=%%</td>
    <td>%%=Lookup("Wish_List_Item__c","Product_Quantity__c","Id",@prodctid)=%%</td>
  </tr>

%%[next @j  

]%%

%%[
next @i ]%%


</table>
2

You have to used Field and Row AmpScript function to get the each matching records.

%%[
SET @ID = AttributeValue("Id")
SET @Count = LookupRows('Wish_List_Item__c','Wish_List__c',@ID)

IF RowCount(@Count) > 0 Then
    For @i = 1 to RowCount(@Count) DO
]%%
    <tr>
        <td>%%=Field(Row(@Count,@i),"Name")=%%</td>
        <td>%%=Field(Row(@Count,@i),"Product_Code__c")=%%</td>
        <td>%%=Field(Row(@Count,@i),"Product_Quantity__c")=%%</td>
    </tr>   
%%[
    Next @i
EndIf   
]%%
| improve this answer | |
  • Is it possible to retrieve Campaign attributes using AttributeValue method? – jagmohan Sep 1 '16 at 9:15
  • You mean Profile/Preference Attribute ? – Palash Rai Sep 1 '16 at 9:19
  • Well, I'm new to AMPscript, not sure about Profile/Preference. I want to get Campaign Code and then use that in email body. Does that make sense? – jagmohan Sep 1 '16 at 9:21
  • Where is your Campaign Code store? in DataExtension? AttributeValue is a AmpScript function and it only use for check if field is present in DataExtension or not. – Palash Rai Sep 1 '16 at 9:29
  • Campaign Code is on the Campaign record that we create in Marketing Cloud. – jagmohan Sep 1 '16 at 9:31

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.