O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scheduling Tasks with CFSCHEDULE

Besides being able to schedule tasks with the ColdFusion Administrator, you can use the CFSCHEDULE tag to do it programmatically. With the CFSCHEDULE tag, you can add, update, delete, and run scheduled tasks. Scheduling tasks programmatically let’s you add a whole new level of functionality to your applications. For example, you can create a reporting application that allows users to have automatic email delivery of their reports on a scheduled basis. With the CFSCHEDULE tag, it is easy to set things up so that your application automatically schedules a task for each user. And each task can automatically generate a report and email it to the user at a chosen interval.

The attributes used by the CFSCHEDULE tag roughly coincide with the form fields from the Add Scheduler Task page in the ColdFusion Administrator, as you can see in Appendix A.

Adding Tasks

Adding a task to the Scheduler using CFSCHEDULE is a lot like adding a task via the ColdFusion Administrator. The information you enter in the ColdFusion Administrator is the same information you specify for the CFSCHEDULE tag attributes. For example, to schedule a task called MyTask that calls the template located at http://www.example.com/myscript.cfm once a day at 1:30 p.m., you can use the following code:

<CFSCHEDULE ACTION="Update" TASK="MyTask" OPERATION="HTTPRequest" URL="http://www.example.com/myscript.cfm" STARTDATE="#DateFormat(Now( ),'mm/dd/yyyy')#" STARTTIME="13:30:00" INTERVAL="Daily" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required