2

I need to split a row from a DE. The row contents 4 strings, and I want to see the content in a table. Right now I have some code; but doesn't work:

Script

%%[
VAR @Productos<br/>

SET @Productos = AttributeValue('Productos') <br/>
SET @item = TreatAsContent('{{item}}')<br/>
SET @sku = TreatAsContent('{{sku}}')<br/>
SET @qty = TreatAsContent('{{qty}}')<br/>
SET @price = TreatAsContent('{{price}}')<br/>
<br/> ]%%

Inside html:

Product: %%=V(@item)=%% <br/>
SKU:  %%=V(@sku)=%% <br/>
Quantity: %%=V(@qty)=%% unidades <br/>
Price:   %%=V(@price)=%% <br/>

the row the description of the row

Some images of the error and the code of the "Confirmation Email"

the error in the code

The CODE of the EMAIL-CONFIRMATION.html

2
  • you will likely wanna do this via SSJS instead. There is not really a native way to do this in AMPScript. Jul 20, 2018 at 20:38
  • I used ampscript because I did not know how to try to take the information from the "Products" column and show it divided into several columns of a table. Jul 22, 2018 at 16:48

1 Answer 1

8

Guide Template Language does this effortlessly. No need for SSJS, or awkward AMPscript process loops. The following code:

%%[
var @products
set @products = '[{"item":"Elastic love","sku ":"PUL1288MTL0000M","qty":1,"price":69.00},{"item":"Seashore","sku ":"PEN0576MCLMTL0U","qty":1,"price":59.00}]'
]%%

<table border="1">
  <tr>
    <th>Item</th>
    <th>SKU</th>
    <th>Quantity</th>
    <th>Price</th>
  </tr>

{{.datasource products type=variable source=@products}}
   {{.data}}
      {"target":"@products"}
   {{/data}}

  <tr>
    <td>{{item}}</td>
    <td>{{sku }}</td>
    <td>{{qty}}</td>
    <td>{{price}}</td>
  </tr>

{{/datasource}}

</table>

Will produce the following output:

generated table

All you need to do is change my set @products statement to use set @products = AttributeValue('Productos')

8
  • 3
    Great out of the box usage of GTL! Most people (including myself) forget it even exists and miss places it would be the most elegant solution. Jul 21, 2018 at 18:32
  • 1
    I have tested your code but it still does not work. I leave an image so you can see the error that it gives me when I include the code inside my HTML. It is for an order confirmation email, and I can not divide it from the "Products" column, divide it by parts and display them as I want. Now it does not work properly because it does not show me the content. And it gives me the error of the image. I also leave the complete code of the mail. In case something is wrong Jul 22, 2018 at 16:38
  • 1
    If you copy and paste the code I provided, it should work. I've requested permission to the Google Drive link so I can access your HTML file. Jul 22, 2018 at 22:04
  • 1
    Thanks Eliot, I give you the access for the html file in Drive. I tried with "copy-paste" the code. But changing "set products = "AttributeValue('Productos')" and doesn't work. When you saw the code, tell me and I made changes. Jul 23, 2018 at 7:51
  • 2
    Everything works thanks to the inestimable help of Eliot. Once again, the community triumphs over SF's external support. Thanks guys. Jul 23, 2018 at 10:22

You must log in to answer this question.

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