0

I'm using Amspscript and GTL datasource to extract information from a field in a data extension called: cancelled. This field has multiple items in there and within cancelled there is another field called cancellationReason each cancelled item will have its own reason - based on this reason, I would like a piece of content to appear using if statements. However, I'm aware GTL loops over each iteration, and in instances where 5 items have the same cancellationReason, the relevant content also appears 5 times for each instance. Is there another way I can do this? Here is my working code along with sample data of cancelled variable and its content:

Variable 'cancelled' And JSON data:

[
   {
      "productTitle":"Fan",
      "sku":"fan1",
      "cancelledQty":1,
      "cancellationReason":"Failed"
   },
   {
      "productTitle":"Hat",
      "sku":"fan1",
      "cancelledQty":1,
      "cancellationReason":"Failed"
   },
   {
      "productTitle":"Teabags",
      "sku":"tea1",
      "cancelledQty":10,
      "cancellationReason":"unknown"
   },
   {
      "productTitle":"paint",
      "sku":"paint1",
      "cancelledQty":10,
      "cancellationReason":"unknown"
   }
]

Email Code using json datasource to extract the information:

%%[
VAR @jsonCancellations
SET @jsonCancellations = [cancellations]
]%%

{{.datasource jsonCancellations type=variable maxRows=5000}}
{{.data}}
{"target": "@jsonCancellations"}
{{/data}}

  {{#if jsonCancellations.cancellationReason == "Failed"}}
<p>CONTENT 1 </p>
  {{/if}}

  {{#if jsonCancellations.cancellationReason == "unknown"}}
<p>CONTENT 2 </p>
  {{/if}}
{{/datasource}}

0

You must log in to answer this question.

Browse other questions tagged .