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.

Create Schedule by Script
#1
Hi,

I need to create a lot of schedules and I have not found to do it by script in the forum. Is that possible?

Thanks!!
Reply
#2
It's possible to do via db queries. The easiest approach is to duplicate existing schedule and change the mapped object. I can provide an example if this works for you.
Reply
#3
(04.01.2022, 16:21)admin Wrote: It's possible to do via db queries. The easiest approach is to duplicate existing schedule and change the mapped object. I can provide an example if this works for you.

Ok thanks!! Could you provide me the example?
Reply
#4
Use this function to duplicate a scheduler.
Arguments:
1. id - source scheduler ID
2. address - object to map the new scheduler to
3. name - new scheduler name (optional)
Code:
function copyscheduler(id, address, name)
  local scheduler = db:getrow('SELECT * FROM schedulers WHERE id=?', id)
  local events = db:getall('SELECT * FROM scheduler_events WHERE scheduler=?', id)

  if scheduler then
    scheduler.id = nil
    scheduler.name = name or (scheduler.name .. ' copy')
    scheduler.object = buslib.encodega(address)

    db:insert('schedulers', scheduler)
    local newid = db:getlastautoid()
    for _, event in ipairs(events) do
      event.id = nil
      event.scheduler = newid
      db:insert('scheduler_events', event)
    end
  end

  io.writefile('/tmp/lm-scheduler-clear', '')
end

-- duplicate scheduler ID 1, map it to 1/1/1 and set name to 'test2'
copyscheduler(1, '1/1/1', 'test2')
Reply


Forum Jump: