0

I need to identify which products a subscriber has in data file field so I don't show him/her the same products in the email. e.g. the column header called "Products" has this value: product 1 || product 2 || product 4 || product 7. In this case this subscriber will receive 3, 6 and 8.

They use || in between products as per my example.

How can I identify what products are there through AMPscript?

Thanks, Vic

3

Please utilizing the BuildRowSetFromString() AmpScript function.

Here's a quick example:

%%[ SET @productValues = BuildRowsetFromString("product 1 || product 2 || product 4 || product 7","||") For @i = 1 to RowCount(@productValues) DO SET @Row = Field(Row(@productValues, @i),1) outputline(concat("<br>Product:", @Row)) Next @i
]%%

Output: Product:product 1 Product: product 2 Product: product 4 Product: product 7

  • Thanks Palash, but I need each product assigned to a variable, i.e. @product1, product2, ..., product7. How can I do that? – Snowalker Aug 14 '15 at 10:51
0

Hope this code will work for you.

%%[

 SET @productValues = BuildRowsetFromString("product 1 || product 2 || product 4 || product 7","||")
For @i = 1 to RowCount(@productValues) DO
    SET @Row = Field(Row(@productValues, @i),1)

    If IndexOf(@Row,"1")!=0 Then
        SET @Product1 = @Row
    ElseIf IndexOf(@Row,"2")!=0 Then
        SET @Product2 = @Row
    ElseIf IndexOf(@Row,"3")!=0 Then
        SET @Product3 = @Row
    ElseIf IndexOf(@Row,"4")!=0 Then
        SET @Product4 = @Row
    ElseIf IndexOf(@Row,"5")!=0 Then
        SET @Product5 = @Row
    ElseIf IndexOf(@Row,"6")!=0 Then
        SET @Product6 = @Row
    ElseIf IndexOf(@Row,"7")!=0 Then
        SET @Product7 = @Row
    ElseIf IndexOf(@Row,"8")!=0 Then
        SET @Product8 = @Row
    EndIf

Next @i

]%%

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.