Scroll

Create a Schedule with the .NET Api

The following is a quick explanation for how to create a Schedule using the Exago .NET Api.

Introduction

First, ensure that your application is referencing the Report and Scheduler classes, which are located in the WebReports.Api.Reports and WebReports.Api.Scheduler namespaces, respectively. Additionally reference the C# List class, located in System.Collections.Generic.

using WebReports.Api.Reports;
using WebReports.Api.Scheduler;
using System.Collections.Generic;

Example

/* Manually Creating a Schedule */
Report myReport = (Report)myApi.ReportObjectFactory.LoadFromRepository(@"Reports\WeeklyReport");

List<DayOfWeek> days = new List<DayOfWeek> { DayOfWeek.Monday };
TimeSpan time = new TimeSpan(9, 0, 0);
List<string> emailList = new List<string>
{
"alice@company.com",
"bob@company.com"
};
SchedulerEmailInfo emailInfo = new SchedulerEmailInfo(emailList);

myReport.ExportType = wrExportType.Pdf;
myApi.ReportObjectFactory.Active = myReport;

myApi.ReportScheduler.CreateWeeklySchedule("Monday Meeting", 1, days, DateTime.Today, time, emailInfo);

Breakdown

In this example, we schedule a report to run Weekly on Monday at 9am, and email the output as a pdf to several email addresses.

The ReportObjectFactory contains several overloaded helper methods for creating schedules. For the full list, see the .NET Api. In our example, we use CreateWeeklySchedule, specifically an overload which does not ask for an end date, so the schedule recurs weekly until it is deleted.

This method call requires the following parameters:

CreateWeeklySchedule(string name, int everyNWeeks, List<DayOfWeek> days, DateTime rangeStartDate, TimeSpan? schedTime, SchedulerEmailInfo emailInfo);

Name

A name to refer to the schedule. This is what will show up in the schedule manager.

everyNWeeks

An int which specifies how often the schedule will recur. 1: Every week, 2: Every other week, etc.

days

A DayOfWeek enum or list of DayOfWeek enums which specify on which days of the week the schedule will recur.

rangeStartDate

A DateTime object for the day and time which the schedule will start. If schedTime is null, the schedule will recur on the given time.

schedTime

A TimeSpan struct for the time which the schedule will recur. If this is null, the schedule will use the time given in rangeStartDate.

emailInfo

A SchedulerEmailInfo object containing the following objects:

  • List<string> toAddr: To- addresses.
  • List<string> ccAddr: CC- addresses (optional).
  • List<string> bccAddr: BCC- addresses (optional).
  • string subject: Email subject line (optional).
  • string body: Email body text (optional).

After filling out the necessary fields, we need to do some maintenance tasks to ensure the schedule is created correctly.

The Create Schedule methods work on the "Active" report. This is usually the last report accessed or modified. To ensure we are calling the correct report, we can manually set the active report by passing the report object to myApi.ReportObjectFactory.Active.

Finally, we need to ensure that the report executes in a format supported by the scheduler. The scheduler cannot execute in the browser-based Html format, so we'll set the myReport.exportType to PDF.


Hidden Article Information

Article Author
Exago Development
created 2016-04-11 19:20:21 UTC
updated 2017-02-21 16:45:52 UTC

Labels
How Do I, API, .NET, scheduler, save scheduled reports, creating a schedule, How-To,
Have more questions? Submit a request