I have an xml field in a DE that contains order product data. I only want to show the products from that order that have an xml value ofclothing. Is there a way to write a loop to cycle through these products and only show those with the value of clothing?

I have a loop that writes all products ordered, but I don't know if there's a way to just cycle through and write only those with the category value of "clothing". From what I gather, that would be a Do/while loop which isn't supported in ampscript. Can anyone confirm?

  • Yes, do/while loops are not supported in AMPscript. Without seeing the data it’s hard to tell whether there’s a different way to achieve what you’re trying to do - please post the code and some example data.
    – zuzannamj
    Commented Aug 1, 2020 at 6:49

1 Answer 1


I am going to assume that the products are fairly simply defined. I am also going to assume that you know how to use the BuildRowSetFromXML function as you stated you already have a loop that writes all products ordered.

It honestly just sounds like you need a conditional in there around the output section to validate the product.

Something like:

FOR @i=1 TO Rowcount(@myRowSet) DO
  set @row = (@myRowSet,@i)
  set @val = Field(@row,1)

  if IndexOf(@val,'clothing') > 0 then
    OUTPUT(CONCAT("Clothing item: ", @val))

Which will only run the output if the value of val contains the word clothing in it. Now be aware there can be false positives if two words combine to make your word. for instance if you had a product named ClakcloThing, that would match with the indexOf() above and say it is to be output. So if you keep those exceptions in mind, this should handle your needs.

Now this can be process heavy if you are looking at a ton of loops or a ton of iterations, but in that case, you will likely want to utilize SQL or some other server-side data manipulation before-hand to better prep your data.

  • 1
    You are correct! Thank you! Don't know why I didn't think If statement. It was a friday and my brain checked out : )
    – user55293
    Commented Aug 1, 2020 at 17:14

You must log in to answer this question.

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