Macro for reporting activities in email notification

Megan Swan asked on February 9, 2016 01:02

Hi there We are trying to add 24hrs of a users activities to our email notification. We are currently using the macro: {% OnlineMarketingContext.CurrentContact.Activities #%} which displays ALL history, and not in the correct order. Does anyone know what I'd use to get it to display the last 24hrs only and in the correct order? Thanks :)

Recent Answers


Brian McKeiver answered on February 9, 2016 05:40

You can try this:

OnlineMarketingContext.CurrentContact.Activities.Where("ActivityCreated >= DATEADD(dd, -1, GETDATE())").OrderBy("ActivityCreated DESC").TopN(10)

But beware, this is not optimized and could take quite a while to calculate. I'm also limiting it to 10 rows just in case.

2 votesVote for this answer Mark as a Correct answer

Megan Swan answered on February 9, 2016 06:05

Thank you so much for responding Brian! We gave it a try but it came through blank. Any ideas?

0 votesVote for this answer Mark as a Correct answer

Brian McKeiver answered on February 9, 2016 22:53

Megan, which version of Kentico are you using? My snippet was for 9.0.

0 votesVote for this answer Mark as a Correct answer

Megan Swan answered on February 10, 2016 22:58

Oh sorry, we are on 8.2.

0 votesVote for this answer Mark as a Correct answer

Brian McKeiver answered on February 11, 2016 05:43

Hmm it worked for me in 8.2 as well. So when you run your original macro you see all of the results, correct? And not blank? If so, could you tell me if in your Activities object you still see a ActivityCreated field ? Also try just removing the OrderBy or TopN chains in the expression and see if its one of those ?

0 votesVote for this answer Mark as a Correct answer

Megan Swan answered on February 12, 2016 04:07

After trying what you suggested & more we stumbled upon the fact it was a rights issue, I don't have full admin rights (https://docs.kentico.com/display/K82/Reference+-+Macro+methods under "Where" for anyone experiencing the same issue). After asking admin to hit save for me, it worked. Thanks so much for your help Brian, much appreciated!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.