0

I am trying to write an AMP script where I need to display Category types based on different Category's. The column may contain multiple categories, thus the output should be all category types concatenated.

For Eg:

enter image description here

The contact may or may not have multiple categories assigned to them in one column separated by ';' I need to display the text under category type column for respective category, if contact has multiple categories it should display all associated Category Type texts. Below is the sample AMP script I build, but there will be lot of combinations to cover all of it, is there any simple way to do it?

    %%[

var @emailSub, @Category

set @Category= [Category]

IF @Category == 'AB'
THEN
set @emailSub = "Text for AB"
ELSEIF @Category == 'BC'
THEN
set @emailSub = " Text for BC"

ELSEIF @Category== 'AB;BC' 
THEN
set @emailSub = "Text for AB " + "Text for BC"

ELSEIF @Category== 'AB;BC;CD' 
THEN
set @emailSub = "Text for AB " + "Text for BC" + "Text for CD"

ENDIF

]%%
1
  • 1
    I’d put @category into a BuildRowsetFromString function and then loop through it. Inside the loop do a lookup to display the texts for each category.
    – zuzannamj
    Dec 9, 2020 at 15:24

1 Answer 1

1

I have done this using the below approach -

  1. Create a DE named "Category_test" and field (Category and Category Type)where all the categories and their corresponding category type values are stored.
  2. Create another DE which will be your sendable DE containing field "Category".
  3. Use below code snippet as it is or modify as per your specific needs
%%[
var @categoryList, @rows, @row, @rowCount, @category, @i,var @emailSub
set @emailSub = ""
set @categoryList = Category

set @rows = BuildRowsetFromString(@categoryList,";")
set @rowCount = rowCount(@rows)

if @rowCount > 0 then

  for @i = 1 to @rowCount do

    var @category
    set @row = row(@rows, @i) /* get row based on counter */
    set @category = field(@row,1)
    set @temp = Lookup("Category_Test","Category Type","Category",@category)
    set @emailSub = concat(@emailSub," ",@temp)

    ]%%

    %%[

  next @i ]%%

%%=v(@emailSub)=%%

%%[ else ]%%

No Category Found

%%[ endif ]%%
3
  • Thank you for your answer, this script does works but only shows the Category of first found Category Type. Eg: If Category = AB;BC , it displays Category Type of AB only and not BC.
    – seeker
    Dec 14, 2020 at 10:21
  • I created a row with value "AB;BC" against Category Field in Sendable DE and did preview and test and it seems to be working as the output that I received was "Text for AB Text for BC". Are u trying with the same value that I tried. Dec 14, 2020 at 14:29
  • Yes, the sendable DE contacts values like 'AB;BC' and the other DE which holds Category and Category Type are the way displayed in image. What I get is the value of AB only and not BC (first found category's value)
    – seeker
    Dec 18, 2020 at 8:42

You must log in to answer this question.

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