This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Scheduler control via script
#1
Hello,

I need to be able to delete events from a scheduler using a script.

I'd like to be able to delete a specific event and also delete all of them.
To create them, I'm using the script I found on the forum:


webrequest = require('webrequest')

data = {
  value = '0', -- value to send
  scheduler = 8, -- parent scheduler ID
  name = 'new event',
  active = 'on', -- 'on' or 'off'
  type = '', -- '' (run at specific time), 'sunrise' or 'sunset'
  start_hour = 13, -- only for run at specific time
  start_min = 0, -- only for run at specific time
  offset_hour = -1, -- only for 'sunrise' or 'sunset'
  offset_min = 30, -- only for 'sunrise' or 'sunset'
  year = 0, -- 0 = all years, specific year otherwise
  months = '111111111111', -- Jan to Dec, 1 = on, 0 = off
  daysofmonth = '1111111111111111111111111111111', -- 1..31, 1 = on, 0 = off
  daysofweek = '1111111', -- Monday to Sunday, 1 = on, 0 = off
  dayweeknrs = '111111', -- week 1 to 5 in month, 6th value = Last week of the month, 1 = on, 0 = off
  holidays = '', -- '' (don't care), 'y' (run on holidays), 'n' (don't run on holidays)
}

res, err = webrequest('schedulers', 'events-save', { data = data })
log(res, err)

Thanks!!
Reply
#2
To delete events use 'events-delete' and data = { id = EVENT_ID } respectively.

Use this code to get all events for a particular scheduler:
Code:
scheduler_id = 123
ids = db:getlist('SELECT id FROM scheduler_events WHERE scheduler=?', scheduler_id)
for _, id in ipairs(ids) do
  log(id)
end
Reply


Forum Jump: