Conditional Sending of a Dynamic Newsletter

Pablo Alejo asked on October 14, 2014 16:17

Is there anyway to send a newsletter conditionally? For example, I have a newsletter that needs to go out weekly but if no items were published in the last week then the newsletter shouldn't go out.

Thanks in advance.

Correct Answer

Zach Perry answered on October 15, 2014 15:35

If you set the page title that the dynamic newsletter uses to ##DONOTSEND## the newsletter won't send. I created a custom macro to determine if the newsletter should send.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on October 15, 2014 14:23

Guess I haven't run across this before but you'd think if there were no new issues for that newsletter, it wouldn't send. Have you tried/tested that? What results did you see? If it doesn't work by default the way we're both thinking, a global event handler would be where I'd start to look to handle this.

0 votesVote for this answer Mark as a Correct answer

Pablo Alejo answered on October 15, 2014 16:02

Hey Zach, That is exactly what I did. I created a custom macro that made the conditional test i wanted and if not true then it put the ##DONOTSEND## into the page title.

0 votesVote for this answer Mark as a Correct answer

Mark Elliott answered on January 30, 2015 19:24 (last edited on December 10, 2019 02:30)

Can you give an example of the custom macro you created to do this? I've written an expression that says

{%if (CurrentDocument.Items.Count> 0) {"PageTitle"} else {"##DONOTSEND##"}|(identity)GlobalAdministrator%}

but it always evaluates to the false condition no matter if the page contains content or not.

0 votesVote for this answer Mark as a Correct answer

Pablo Alejo answered on January 30, 2015 22:53 (last edited on December 10, 2019 02:30)

Hey Mark,

I'm doing the following...

{% if (!IsRecentResearch()) { "##DONOTSEND##" } |(identity)GlobalAdministrator%}

where IsRecentResearch() is a custom macro doing all of the work. The macro code is...

[MacroMethod(typeof(bool), "Determines if a there have been any new blog posts in the last week", 1)]
public static object IsRecentResearch(EvaluationContext context, params object[] parameters)
{
    return Helper.GetRecentResearchCount() > 0;
}

and that calls the helper method that is...

public static int GetRecentResearchCount()
{
    return DocumentHelper.GetDocuments("custom.ResearchItem").Count(b => b.GetDateTimeValue("BlogPostDate", DateTime.Now) >= DateTime.Now.AddDays(-7));
 }

This works on version 8.1.2. What version are you on?

When I run your macro, I get a blank value for the CurrentDocument.Items.Count and therefore it's always going be false.

What are you trying to accomplish with your macro?

0 votesVote for this answer Mark as a Correct answer

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