1

I am trying to create an abandoned cart journey, where on the bottom of the email, the items left in the cart by the person, would be listed below each other. There is no maximum limit of items one can have left in their basket. I have the abandoned cart data coming into Salesforce Sales Cloud, and the IDs of the products that are left in the basket are populated in a custom text field (Last_abandoned_cart_lineitem_Product_IDs), separated by commas (etc. 6569307013328,6569349873872,6645332050128).

In Marketing Cloud, I have a data extension named "EcommerceProductImageUrls", which contains the Product titles, IDs and image urls of all of the products we have in our online store. I am attempting to create AMPscript that would look up the product titles and image urls from the DE of the products left in the cart, based on the product IDs in the Salesforce field. I have managed to get the code to the point where if the field contains only one product id, the image and the title is shown in the email. But I can't figure out how to do it, if the field contains multiple product ids, separated with a comma? All of the product ids in the custom field should be looked up and stacked below each other in the email. I also don't know how I then get the images and titles to be listed below each other, when the number of products one can have in their basket is not fixed?

Here is the code I have managed to write so far (please excuse me, I am new to AMPscript):

%%[

var @ProductID, @ProductTitle, @ProductImageURL, @rows, @row, @rowCount

Set @ProductID = AttributeValue('Account:PersonContact:Last_abandoned_cart_lineitem_Product_IDs__c')
Set @rows = LookupRows("EcommerceProductImageUrls", "ProductID", @ProductID)
Set @rowCount = rowcount(@rows)

if @rowCount > 0 then

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

]%%


      <center><img style="border: 0;display: block;height: auto;width: 150px;max-width: 1200px;" alt="" width="150" src="%%=Field(@row, "ProductImageURL")=%%"></center>

<p style="text-align: center; font-size: 16px">
  <span style="color: #FFFFFF">%%=Field(@row, "ProductTitle")=%%</span>
</p>
   

%%[ next @i ]%%

%%[ else ]%%

%%[ endif ]%%
1
  • 2
    First, if multiple ids are stored "@ProductID" you must be split into ids with set @ids = BuildRowsetFromString(@ProductID, ","). Then for each of this ids a simple lookup to you catalog gives you the infos related to each product. Your display code should display them then. Commented Aug 26, 2022 at 8:21

1 Answer 1

1

Use BuildRowsetFromString to split your delimited string into Ids.

Try this :

%%[
    var @ProductID, @Product, @ProductRecord, @Ids
    Set @ProductID = AttributeValue('Account:PersonContact:Last_abandoned_cart_lineitem_Product_IDs__c')
    set @Ids = BuildRowsetFromString(@ProductID, ",")
    FOR @i = 1 to ROWCOUNT(@Ids) DO
        SET @ProductId = Field(ROW(@ids, @i),1)
        SET @Product = LookupRows("EcommerceProductImageUrls", "ProductID", @ProductID)
        SET @ProductRecord = row(@Product, 1)
]%%
    <center><img style="border: 0;display: block;height: auto;width: 150px;max-width: 1200px;" alt="" width="150" src="%%=Field(@ProductRecord, "ProductImageURL")=%%"></center>
    <p style="text-align: center; font-size: 16px"><span style="color: #FFFFFF">%%=Field(@ProductRecord, "ProductTitle")=%%</span></p>
%%[ next @i ]%%

See here and here for further details on how to split delimited strings.

Of course add the correct checks on max values and non empty strings.

6
  • Thank you so much for your help. I corrected the code as you suggested, but now keep receiving this error message. Any idea what causes this? Invalid object property name. Object Type: System.Data.DataRow[] Property Name: ProductImageUrl Commented Aug 26, 2022 at 10:08
  • Looks like the name of the URL field in you catalog DE (EcommerceProductImageUrls) is not "ProductImageURL" Commented Aug 26, 2022 at 10:12
  • That's right, it is actually "ProductImageUrl", but I corrected that to the code, and it still gives the same error message. <center><img style="border: 0;display: block;height: auto;width: 150px;max-width: 1200px;" alt="" width="150" src="%%=Field(@Product, "ProductImageUrl")=%%"></center> <p style="text-align: center; font-size: 16px"> <span style="color: #FFFFFF">%%=Field(@Product, "ProductTitle")=%%</span> Commented Aug 26, 2022 at 10:23
  • Yes, corrected the code to correct this. Your issue was related to splitting a delimited string, so I did not investigate the rest of the code. LookupRows can return several rows. In your case we know the product_id is unique, so there is only one record, which as to be extracted from the result (it is the first row). Commented Aug 26, 2022 at 11:23
  • If this solves your issue, please ✓ validate this answer. Else feel free to ask for more details. Commented Aug 26, 2022 at 11:26

You must log in to answer this question.

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