# Scripting Perspective to add events for Equipment Schedule

**URL:** <https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 2, 2023, 8:44pm UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511 "2023-06-02T20:44:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 2, 2023, 8:44pm UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/1 "2023-06-02T20:44:27Z")

</div>

I am trying to use the equipment schedule in perspective for employees to see what they have done throughout the day for various jobs. I have two items right now one for their jobs and another for indirect chores. What I am trying to do is script something on the Startup event to load in all the information into the schedule.

Below is what I currently have wanting to add this item array to the scheduled Events. I am pulling all of this from a Named query but don't know why it is not even making the array of items.

```auto
def runAction(self):
	emp_num = self.session.custom.JW.employeeNQ.emp_num
	transParameters = {"emp_num": emp_num, "status": 'C'}
	data = system.db.runNamedQuery ("Select_Jer_JW_TransStaging", transParameters)
	pyTrans = system.dataset.toPyDataSet(data)
	for row in pyTrans:
		if {session.custom.JW.transNQ.trans_type} == 'R':
			item = {
				"endDate": pyEmpTbl.getValueAt(row, "date_last_modified"),
				"startDate": pyEmpTbl.getValueAt(row, "date_created"),
				"itemId": 'work',
				"eventId":pyEmpTbl.getValueAt(row, "job"),
				"backgroundColor": rgb(116,159,174) 
				
			}
		else:
			item= {
				"endDate": pyEmpTbl.getValueAt(row, "date_last_modified"),
				"startDate":pyEmpTbl.getValueAt(row, "date_created"),
				"itemId": 'InD', 
				"eventId": pyEmpTbl.getValueAt(row, "ind_code"),
				"backgroundColor": rgb(0,128,0)
			}
		scheduledEvents.append(item)

```

In addition if someone can figure out why it is not making the array also how to add the items array to the scheduleEvents?

---

<div class="post-metadata">

**Author:** ![YF129701](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yf129701/32/60498_2.png) [@YF129701](https://forum.inductiveautomation.com/u/YF129701)\
**Post date:** [June 2, 2023, 8:53pm UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/2 "2023-06-02T20:53:02Z")

</div>

I ran into this issue before when I wasn't referencing the correct `itemId`'s in my scheduled events query. Are you sure you have at least two `itemId`s, one called `work` and one called `InD`? Those need to be configured beforehand (they correspond to the "rows" in the equipment schedule).

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 2, 2023, 8:57pm UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/3 "2023-06-02T20:57:37Z")

</div>

I manually put in the items ID in the perspective property editor so they are in there and the label associated with the ids are both popping up for the rows in the schedule.

I have also tried the below code as well I don't know if this helps but it also does not work.

```auto
def runAction(self):
	emp_num = self.session.custom.JW.employeeNQ.emp_num
	transParameters = {"emp_num": emp_num, "status": 'C'}
	data = system.db.runNamedQuery ("Select_Jer_JW_TransStaging", transParameters)
	pyTrans = system.dataset.toPyDataSet(data)
	
	self.props.scheduledEvents = []
	
	for row in pyTrans:
		if row ["trans_type"] == "R":
			system.perspective.print("items started")
			items = {
				"endDate": row["date_last_modified"],
				"startDate": row["date_created"],
				"itemId": 'work',
				"eventId": row ["job"],
				"backgroundColor": rgb(116,159,174) 
			}
			
			system.perspective.print(items)
		else:
			items = {
				"endDate": row["date_last_modified"],
				"startDate": row["date_created"],
				"itemId": 'InD', 
				"eventId": row ["job"],
				"backgroundColor": rgb(0,128,0)
			}
		self.props.scheduledEvents.append(items)

```

it is starting the for loop and going into the if statement but not creating the items array so it won't even print into the console.

---

<div class="post-metadata">

**Author:** ![humphrey.daniel](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@humphrey.daniel](https://forum.inductiveautomation.com/u/humphrey.daniel)\
**Post date:** [June 3, 2023, 2:09am UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/4 "2023-06-03T02:09:21Z")

</div>

It appears you're missing quotes around the keys for itemId and backgroundColor in the else section.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 5, 2023, 11:48am UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/5 "2023-06-05T11:48:42Z")

</div>

Unfortunately, after changing that it is still not the problem. It is going into the if statement but not adding the array objects to items

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 5, 2023, 11:52am UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/6 "2023-06-05T11:52:46Z")

</div>

Grace, can you edit both of your posts (pencil icon) to fix the code formatting so we can check for indentation errors. Select the code block and press the \</\> button on the editor toolbar.  
Thanks.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 5, 2023, 12:07pm UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/7 "2023-06-05T12:07:17Z")

</div>

sounds great just did

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 5, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/scripting-perspective-to-add-events-for-equipment-schedule/74511/8 "2023-06-05T18:17:42Z")

</div>

thank you for all the help i was able to figure out the error in needing to creating different bindings
