0

I want to start out by saying I am new to AMPScript though I have a lot of programming/scripting experience. I am trying to figure out a way to do the following.

I have a customer who has multiple (could be any number) products associated with them. Right now I receive a delimited file that list give a user id and then all the product fields delimited by a "|". If a customer has more than one product associated with them there will be a separate line in the file for each product.
What I need to do is to import this file into ExactTarget and then generate an email for each customer based on this data. Most of this is pretty easy besides the multiple products. I was hoping some guidance could be provided on using AMPScript in a template to generate a chunk of HTML for each product that is associated to the customer (this will vary per customer).

3
  • Any input would be greatly appreciated.
    – Gondore
    Apr 11, 2014 at 19:29
  • @Adam Springs Did you get any solution for this issue. I am looking into the same issue as we have multiple line items in an Order and we are importing those orders through data extension and not sure how to handle the multiple lines in email.
    – Harry
    Jun 18, 2018 at 3:38
  • My answer below outlines it. Jun 18, 2018 at 17:55

2 Answers 2

1

If you imported this Product data into a Product Data Extension, and you're sending to another Data Extension that's related by User_id, then you can simply use one of the AMPScript lookup functions to output the data in the email.

Something like this:

%%[
var @rows, @row, @rowCount, @numRowsToReturn, @UserId, @i

set @UserId = AttributeValue("user id")
set @numRowsToReturn = 0 /* 0 means all */
set @rows = LookupOrderedRows("Products",@numRowsToReturn,"SKU desc, qty asc","user id", @UserId)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then

for @i = 1 to @rowCount do

    var @SKU, @qty
    set @row = row(@rows,@i) /*get row based on loop counter */
    set @SKU = field(@row,"SKU")
    set @qty = field(@row,"qty")

]%%

    <br>Row %%=v(@i)=%%, SKU: %%=v(@SKU)=%%, Qty: %%=v(@qty)=%%

%%[

next @i ]%%

%%[ else ]%%

No products found

%%[ endif ]%%

Reference

-1

Checkout this document, specifically page 127: http://memberlandingpages.com/docs/AMPscript_Guide.pdf

It shows a nice of example of looping through data from a data extension, which sounds like what you're wanting to do with order/product data.

You must log in to answer this question.

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