1

I have created DNN scheduled task on my website to generate a report of all users created since the last run of the task. I want to do this so that the report can be configured to generate daily, weekly, monthly or any other duration, just by changing the properties of the scheduled task in DNN. My problem is that I am not sure how to get the "last run date" of a task inside my dll. It is not clear if this is possible, and if it is, then which property of the ScheduleHistoryItem object I should use. (DNN v5.6.2)

Apeksha
  • 485
  • 6
  • 23

1 Answers1

2

Yes it is possible. Once you have pulled the list of ScheduleHistoryItems you want via the SchedulingProvider.Instance().GetScheduleHistory function, you can sort the list by the built in ScheduleHistorySortStartDate IComparer. The function below will return the last ScheduledHistoryItem that ran, which you can then check the EndDate property of the result to determine when the task last completed.

public DotNetNuke.Services.Scheduling.ScheduleHistoryItem GetLastScheduleHistoryItem(int ScheduleId = -1)
{
System.Collections.ArrayList scheduleHistory = DotNetNuke.Services.Scheduling.SchedulingProvider.Instance().GetScheduleHistory(ScheduleId);
if (scheduleHistory != null)
{
    scheduleHistory.Sort(new DotNetNuke.Services.Scheduling.ScheduleHistorySortStartDate()); //Sort the returned results by the Start Date

    if (scheduleHistory.Count > 0)
        return (DotNetNuke.Services.Scheduling.ScheduleHistoryItem)scheduleHistory[0];

}

return null;
}
Enqueuing
  • 131
  • 8