1

I'm trying to write AMPscript that will arrange content in an email based on a user's score across a number of variables. The higher the score, the higher the positioning within the email.

For example, the categories/columns could be:

Baseball - Basketball - Soccer - Tennis - Hockey - Golf

And each user would have a value in the column per sport.

I'd like to re-order stored content so that the highest-valued sport is presented first in the email, and then the next highest and next highest and so forth. There may be situations where there is no content available for the sport, in which case I'd like to move to the next highest score or insert content in a default way.

Some more data as background:
article1 = baseball
article2 = baseball
article3 = basketball
article4 = soccer
article5 = soccer
article6 = tennis
article7 = hockey
article8 = baseball
article9= golf
                                  Baseball -- Basketball -- Soccer -- Tennis -- Hockey -- Golf
[email protected]         35              0               15             0             20         15
[email protected]         2              40               55             0             12         3
[email protected]          55             0                0               0            40         45

Using the example above,
JOHN DOE's Email would have:
ARTICLE 1, 2, 8, 7, 4, 5, 9, 3, 6

JANE DOE's Email would have:
ARTICLE 4, 5, 3, 7, 9, 1, 2, 6, 8, 10

JACK DOE's Email would have:
ARTICLE 1, 2, 8, 9, 7, 3, 4, 5, 6, 10


Complicated? Yes! Doable? Should be!
Show a little AMPscript love!

1
  • 2
    Welcome to SFSE - feel free to personalize your user name and feel at home here! Commented Apr 25, 2014 at 14:29

2 Answers 2

1

I agree with Timothy that it would be better to do your segmentation and order manipulation in QueryActivities before the send time, but this approach is possible if you have your articles sitting somewhere in DE.

Even further based on whether or not there is only a limited number of permutations for order (say if you only have 6-10 sports covered) you can pre-generate all of those permutations and then retrieve these for the subscriber based on their preference set.

In AMPScript you can iterate over the preferences of the user, concatenating the sport preference in the "right" order, e.g. in your case for John you'd end up with Baseball|Basketball|Soccer|Tennis|Hockey|Golf string. You'd then split this string with BuildRowSetFromString (see reference for the function) and outputting articles based on the order of the user preferences.

Would be great to know how you actually produce articles (e.g. do they come from a specific content area, data extension or you build them on the fly) as it would help to suggest best performing outcome.

3
  • Thanks for the additional feedback, Vlad -- that helps me visualize what Timothy may have been referencing. The articles are really just snippets, where we insert a headline, image URL, and some teaser content that is stored within a DE.
    – user7827
    Commented Apr 28, 2014 at 3:11
  • Right, so then you should definitely be able to get the pre-defined outcomes configured before getting the data out to the email. Just to be clear - your article is some HTML block, where you have placeholders for headline, image and content right?
    – Vlad
    Commented Apr 29, 2014 at 11:57
  • Yes - an HTML block where we have placeholders for the headline, image and content. Those are stored in the DE that is referenced in the HTML. We have a big launch happening this week - I'll try this again next week.
    – user7827
    Commented Apr 29, 2014 at 19:11
0

My hunch is that your data is too complicated to just use AMPscript to manipulate. Do all your segmenting with QueryActivities into a new sendable data extension, and send to that.

1
  • At the moment we create "segment" DEs to deploy to (using the example above, a BASEBALL DE, BASKETBALL DE, etc), but it doesn't cover individual situations. For example, you might like BASEBALL best, but what follows is unique for everyone.
    – user7827
    Commented Apr 26, 2014 at 1:01

You must log in to answer this question.

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