Users schedule including a parameter date

According to a parameter date, can we obtain all users with a schedule including this date ???

You can, but it would be a really ugly amount of scripting. It wouldn’t be a bad idea if we made this a little easier for you – let me think a bit about what would benefit the most users and I’ll make a ticket. This should be pretty easy for us to do.

Yes indeed, the goal is to detect (and display) users will be notified by the alarm notification module according to their schedule.
Any help will be welcome !

Luckily for you I have some new people that needed to learn how to add scripting functions, and this one was easily enough that it made a good teaching tool.

Look for system.user.isUserScheduled() and system.user.getScheduledUsers() in 7.9.7 :smile:

1 Like

Cool, hope this new release will be ready for this Christmas :grinning: :santa:

The beta should be out before then. Code freeze is on Nov 24 for 7.9.7.

Version 7.9.6 will be released in th meantime ??? or user.isUserScheduled() and system.user.getScheduledUsers() will be added in 7.9.6 ?

7.9.6 should come out very soon. It was sent to QA at the end of October, and the last I heard testing was going well.

1 Like

Terrific all these news release in this short time :+1:

I was looking at the same issue today. With some help from the Javadocs, I pieced together how to extract schedule times from the schedules.

Basically, once you get a schedule, you can call ‘getScheduleForDay(java.util.Calendar.getInstance())’ to get a days schedule in the form of a ‘Timeline’ object. Then you pull TimeSegments out of it for the current day.

The code below then pulls java.util.Date values from the segments. Note that there appears to be some mixup in the toString method for the Timeline that shows time segments in EST but with an offset as if they were UTC…I think, lol.

Anyway, here’s some code that you can put into the Script Console if you’re interested to extract the start and end time of a given segment. Then, of course you could iterate through the schedules and segments for a day and compare against the current time. There appear to be some helper methods in the Timelines that may make it a bit simpler, but none of it is well documented and I haven’t tried it.

Anyway, the code:

import datetime
import java.util

# Reference current time from datetime lib
'Today: ' + str(datetime.datetime.now())

# Get List of schedules and pick one
schedules = system.user.getSchedules()
aSchedule = schedules[2]
'Schedule Name: ' + aSchedule.getName()

# Get a Calendar instance represnting now
tod = java.util.Calendar.getInstance()

# Get Timeline from schedule for today
timeline = aSchedule.getScheduleForDay(tod)
'Timeline: ' + str(timeline)

# Get Time Seqments for Today
timelineSegments = timeline.getSegments()
'Segments: ' + str(timelineSegments)

# Grab first segment and get start and end time.
starting = timelineSegments[0].getStart()
ending = timelineSegments[0].getEnd()
'First Segment Start: Long Value -- ' + str(starting)

'Schedule Type: ' + str(aSchedule.getType())

'Schedule Saturday Time Definition: ' + str(aSchedule.getSaturdayTime())

# Use Style object to extract Date values for timeline start and end long values
style = timeline.getStyle()
'Timeline Style: ' + str(style)

style.toDateForStyle(sta)
style.toDateForStyle(ending)

1 Like

Just as a note for future readers, getScheduleForDay() can return null if there’s no schedule for that day. Also it doesn’t take into account schedule adjustments (and it may not take holidays into account – can’t remember at the moment.)

Attempting to use this same code in the process of getting a schedule for a specific date, however something (not sure if its a bug or I am missing something) is causing this to always do everything in relation to today.

If I run this same code, note that I have added 5 days to the date, and somehow this still is always giving me data for today.



import datetime
import java.util


# Get List of schedules and pick one (In this case the schedule I am picking is 0:00-8:00)
schedule = filter(lambda schedule: schedule.name != 'Always', system.user.getSchedules())[-1]

# Get a Calendar instance represnting 5 days in the future
cal = java.util.Calendar.getInstance()
cal.setTime(system.date.addDays(system.date.now(), 5))

# Get Timeline from schedule for the calendar day
timeline = schedule.getScheduleForDay(cal)
'Timeline: %s' % timeline

# Get Time Seqments for 5 days in the future
timelineSegments = timeline.getSegments()
'timelineSegments: %s' % timelineSegments

# Grab first segment and get start and end time.
starting = timelineSegments[0].getStart()
'starting: %s' % starting
ending = timelineSegments[0].getEnd()
'ending: %s' % ending


# Use Style object to extract Date values for timeline start and end long values
style = timeline.getStyle()
'style: %s' % style

start = style.toDateForStyle(starting)
'start: %s' % start
end = style.toDateForStyle(ending)
'end: %s' % end

However this is what prints, though it should be printing March 31st in this case.

u'Timeline: [Thu Jan 01 00:00:00 UTC 1970 -> Thu Jan 01 08:00:00 UTC 1970]'
u'timelineSegments: [Thu Jan 01 00:00:00 UTC 1970 -> Thu Jan 01 08:00:00 UTC 1970]'
'starting: 0'
'ending: 28800000'
u'style: TimeOfDay'
u'start: Sat Mar 26 00:00:00 UTC 2022'
u'end: Sat Mar 26 08:00:00 UTC 2022'

Is there something I am doing that’s inherently locking this to today and I am not realizing it?

I appreciate any help.