0

Our case is inserting multiple orders related to single Customer_Id. The ask here is that we would like to use a complete AMPscript block, if possible, instead of combining inline and block-style in our 'for' loop case, so we could invoke the variables without inserting the AMPscript code as part of the content block. Basically, like we do in other 'lighter' versions of AMPscript and simpler lookups. Here's how our content block looks like with combination of block+inline AMPscript code:

<ul>
%%[

VAR @lineItems, @countLineItems, @Customer_ID, @i, @row

SET @CIP = AttributeValue('Customer_ID')
SET @lineItems = LookupRows('Orders','Customer_ID',@Customer_ID)
SET @countLineItems = RowCount(@lineItems)

IF @countLineItems > 0 THEN

  FOR @i = 1 TO @countLineItems DO
    VAR @row, @item_description, @Quantity_ordered

    SET @row = row(@lineItems, @i)
    SET @item_description = field(@row,'ITEM_DESCRIPTION')
    SET @Quantity_ordered = field(@row, 'Quantity_ordered')
]%%

  <li>%%=v(@item_description)=%%, ordered quantity: %%=v(@Quantity_ordered)=%%</li>

%%[ NEXT @i ]%%
%%[ ELSE ]%%
%%[ RaiseError('No Rows Found!') ]%%
%%[ ENDIF ]%%
</ul>
2
  • There is nothing wrong with your code. What problem are you trying to solve? If the number of line items is dynamic (and there is no maximum number), then it is no option to "flatten" multiple orders per person into one row in your sending data extension. In this case you could use Personalization strings (%%item_description1%%, %%item_description2%% up to your maximum.) Most people are happy they don't have to do this- the flattening is probably a similar async script . You can omit most open/close tags after the inline though: %%[ NEXT @i ELSE RaiseError('No Rows Found!') ENDIF ]%% Commented Jul 23, 2019 at 18:15
  • The code works. Iz had to be added properly into table tags in html.
    – nix9247
    Commented Jul 29, 2019 at 20:55

0

You must log in to answer this question.

Browse other questions tagged .