Change User's Schedule Script

Is there any way to change a user’s schedule via a script?
We have multiple schedules and I would like to change this schedule via a script for a user but can’t find any way to do it.

Any ideas?

You mean like by using system.user.editSchedule()?

No, that edits a schedule, I want to edit a user’s schedule.

Ok, for that I think you’ll have to use a combination of system.user.getUser() and system.user.editUser(). I believe you are going to have to dig into the PyUser class to make it work. I can’t test it right now but I know you can do a get on the ‘schedule’ property, you should also be able to do a set on it to change the users schedule. It would be similar to the example in the editUser() function but instead of adding contact info like shown, you would use the .set() function described in PyUser to set your ‘schedule’ property.

Unfortuanlely the system.user.editUser() is not available in 7.9 which I am using.

Hi ,I know this is an old post but has anyone found out how to modify a user schedule with a script?
I looked in the PyUser class but there is no specific function to modify a user’s schedule.

if it is a database profile you can edit it in the database.

I couldn't find out how to change the user schedule but wanted to post the following example for the next person.

You can call any functions here:
https://files.inductiveautomation.com/sdk/javadoc/ignition784rc1/com/inductiveautomation/ignition/common/user/schedule/BasicScheduleModel.html

I modified the code from the manual to enable Monday, set the time on Monday from 0:00-12:00, and then also modified the schedule description. This takes place on the "Example" schedule given by default. You can run this from a script console to test (on your development server).

# This function prints the response received.
def printResponse(responseList):
    if len(responseList) > 0:
        for response in responseList:
            print "", response
    else:
        print " None"
  
# The main function.
oldScheduleName = "Example"
mySchedule = system.user.getSchedule(oldScheduleName)

if mySchedule != None and mySchedule.getType() == "basic schedule":
    mySchedule.setObserveHolidays(False)
    #mySchedule.setName("MyEditedSchedule")
    mySchedule.setMonday(True)
    mySchedule.setMondayTime("0:00-12:00")
    mySchedule.setDescription("An example of a M-F 8am-5pm schedule with a lunch break but modified")
    response = system.user.editSchedule(oldScheduleName, mySchedule)
    
    warnings = response.getWarns()
    print "Warnings are:"
    printResponse(warnings)
      
    errors = response.getErrors()
    print "Errors are:"
    printResponse(errors)
      
    infos = response.getInfos()
    print "Infos are:"
    printResponse(infos)
else:
    print "Basic schedule", oldScheduleName, "not found."