0

I want to send an email to subscribers that will provide a list of courses where the Courses' end dates are before the subscriber's subscription expiration date. And if the there's no courses applicable for the subscriber, I would want that email to not be sent.

I have a data extension named ActiveCourses that houses all the required courses and their course end dates.

So if there's 6 courses, 4 ends before the subscriber's expiration date, and 2 ends after the expiration date, I want the email to only list the 4 courses. But if all 6 courses ends after Subscriber's expiration date, then don't want the subscriber to receive this email.

Here's the AMPScript I currently have:

%%[
  Set @rows = LookupOrderedRows("ActiveCourses",100,"Start_Date__c", "SubscriptionPlan", @ProgramName)

  if RowCount(@rows) == 0 then
    RaiseError("No Available Courses",true)
  endif

]%%

%%[
 SET @rowcount = RowCount(@rows)
                  
  for @i = 1 to @rowcount do

    Set @row = Row(@rows,@i)
    Set @CourseName = Field(@row,"CourseName")
    SET @CourseStartDate = Field(@row,"hed__Start_Date__c")
    SET @CourseEndDate = Field(@row,"hed__End_Date__c")
   
    IF @CourseEndDate <= @ExpiredDate THEN
]%%

%%=v(@CourseName)=%%
Next Session Dates: %%=FORMAT(@CourseStartDate,'MMMM dd, yyy','Date')=%% - %%=FORMAT(@CourseEndDate,'MMMM dd, yyy','Date')=%%

%%[ ELSE RaiseError("No Available Courses Before Expiration Date",true) ]%%
%%[ ENDIF next @i ]%%

The problem I am facing is that, when I put in RaiseError("No Available Courses Before Expiration Date",true), it will errors out the whole email as soon as there's at least one course after the subscriber's expiration date. I only want the raiseerror to happen if ALL active courses are ending after the subscriber's expiration date.

Is there anyway I can do this?

Thanks

1 Answer 1

0

You could check the rowCount first, then count the active courses. If there are zero active courses, then raise the error. You might need to format the comparison dates, depending on the date types of hed__Start_Date__c and hed__End_Date__c.

%%[

  set @rows = LookupOrderedRows("ActiveCourses",100,"Start_Date__c", "SubscriptionPlan", @ProgramName)
  set @rowCount = rowCount(@rows)

  if @rowCount >  0 then

    set @activeCount = 0

    for @i = 1 to @rowCount do

      set @row = Row(@rows, @i)
      set @CourseName = Field(@row,"CourseName")
      set @CourseStartDate = Field(@row,"hed__Start_Date__c")
      set @CourseEndDate = Field(@row,"hed__End_Date__c")
     
      if FormatDate(@CourseEndDate, "YYYYMMDD") <= FormatDate(@ExpiredDate, "YYYYMMDD") then

        set @activeCount = add(@activeCount, 1)

      ]%%

        <br>%%=v(@CourseName)=%%
        <br>Next Session Dates: %%=FORMAT(@CourseStartDate,'MMMM dd, yyy','Date')=%% - %%=FORMAT(@CourseEndDate,'MMMM dd, yyy','Date')=%%

      %%[ 
      endif

    next @i 

    if @activeCount == 0 then
      RaiseError("No Available Courses Before Expiration Date",true)
    endif

  else 
    RaiseError("No Available Courses",true)
  endif    

]%%
1
  • It worked!!! Thank you soooo much!!
    – Scott Lam
    Jan 30, 2023 at 17:58

You must log in to answer this question.

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