1

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 Aug 1 at 6:49
3

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))
  endif
NEXT @i

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.

| improve this answer | |
  • 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 : ) – chelechele Aug 1 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.