# Change User's Schedule Script

**URL:** <https://forum.inductiveautomation.com/t/change-users-schedule-script/44651>\
**Category:** Ignition\
**Created:** [March 18, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651 "2021-03-18T19:43:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [March 18, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/1 "2021-03-18T19:43:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [March 18, 2021, 7:48pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/2 "2021-03-18T19:48:21Z")

</div>

You mean like by using [system.user.editSchedule()](https://docs.inductiveautomation.com/display/DOC81/system.user.editSchedule)?

---

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [March 18, 2021, 8:00pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/3 "2021-03-18T20:00:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [March 18, 2021, 8:37pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/4 "2021-03-18T20:37:38Z")

</div>

Ok, for that I think you’ll have to use a combination of [system.user.getUser()](https://docs.inductiveautomation.com/display/DOC81/system.user.getUser) and [system.user.editUser()](https://docs.inductiveautomation.com/display/DOC81/system.user.editUser). I believe you are going to have to dig into the [PyUser](http://files.inductiveautomation.com/sdk/javadoc/ignition80/8.0.12/com/inductiveautomation/ignition/common/user/PyUser.html) 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.

---

<div class="post-metadata">

**Author:** ![jramirez3](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jramirez3](https://forum.inductiveautomation.com/u/jramirez3)\
**Post date:** [March 18, 2021, 8:48pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/5 "2021-03-18T20:48:33Z")

</div>

Unfortuanlely the [system.user.editUser()](https://docs.inductiveautomation.com/display/DOC81/system.user.editUser) is not available in 7.9 which I am using.

---

<div class="post-metadata">

**Author:** ![daniele1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/daniele1/32/31531_2.png) [@daniele1](https://forum.inductiveautomation.com/u/daniele1)\
**Post date:** [May 18, 2021, 2:26pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/6 "2021-05-18T14:26:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [May 18, 2021, 2:40pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/7 "2021-05-18T14:40:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [December 14, 2023, 8:11pm UTC](https://forum.inductiveautomation.com/t/change-users-schedule-script/44651/8 "2023-12-14T20:11:16Z")

</div>

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](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).

```auto
# 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."
```
