Scripting Perspective to add events for Equipment Schedule

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.

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?

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 itemIds, one called work and one called InD? Those need to be configured beforehand (they correspond to the "rows" in the equipment schedule).

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.

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.

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

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

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.

sounds great just did

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