Article
· Mar 28 1m read

How to register and reference task schedules programmatically

InterSystems FAQ rubric

Here, we will introduce a sample code for registering and referencing task schedules.

 ①Sample of task schedule registration

*Create a task to execute do ^TEST every day at 1:00 am. 

 set task=##class(%SYS.Task).%New()
 set task.Name="MyTask1"
 set taskDescription="Execute ^xxx every day at 1:00 AM" // Optional
 set task.NameSpace="USER"
 set task.TimePeriod=0
 set task.DailyFrequency=0
 set task.DailyFrequencyTime=""
 set task.DailyIncrement=""
 set task.DailyStartTime=$ZTimeh("01:00:00")
 set task.DailyEndTime=""
 set task.TaskClass="%SYS.Task.RunLegacyTask"
 set task.Settings=$LB("ExecuteCode","do ^TEST") // Set ExecuteCode for RunLegacyTask
 write task.%Save()

② Sample of task schedule reference

*The contents registered in the task schedule are obtained programmatically.

USER>set task=##class(%SYS.Task).%OpenId(1) USER>zwrite tasktask=<object reference="">[14@%SYS.Task]

+----------------- attribute values ------------------
| %Concurrency = 1
| DailyEndTime = 0
| DailyFrequency = 0
| DailyFrequencyTime = ""
| DailyIncrement = ""
| DailyStartTime = 0
| DayNextScheduled = 63877
| DeleteAfterRun = 0
| Description = "Journal files are switched at midnight every day."

// If you want to refer to individual items, do the following:
USER>write $ZDT(task.DayNextScheduled)
11/21/2015
USER>write task.Name
Journal switching
USER>

Discussion (2)2
Log in or sign up to continue