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>
table {
    border-collapse: collapse;

table, td, th {
    border: 1px solid black;

<h2>Wish List Items</h2>


<th>Product Name</th>
    <th>Product Code</th>
    <th>Product Quantity</th>

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)



%%[next @j  


next @i ]%%


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
    Next @i
  • 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.