# Reporting Tag Historian Query Error

**URL:** <https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [August 25, 2023, 3:55am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369 "2023-08-25T03:55:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Kevin\_Dagapioso](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Dan\_Kevin\_Dagapioso](https://forum.inductiveautomation.com/u/Dan_Kevin_Dagapioso)\
**Post date:** [August 25, 2023, 3:55am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/1 "2023-08-25T03:55:35Z")

</div>

I have given an error like this in my report:  
WARN: Error invoking script.Traceback (most recent call last):  
File "function:updateData", line 62, in updateData  
TypeError: list indices must be integers

**NOTE: Line 62 is the last line in the code.**  
Here is my code:

```auto
def updateData(data, sample):
	currentDate = system.tag.readBlocking(['[System]Gateway/CurrentDateTime'])[0].value
	currentYear = data['year']
	dateStart = system.date.addYears(system.date.parse(system.date.format(currentDate,currentYear + "-12-22 08:00:00"),'yyyy-MM-dd HH:mm:ss'),-1)
	endDate = system.date.addYears(system.date.parse(system.date.format(dateStart,currentYear + "-12-22 08:00:00"),'yyyy-MM-dd HH:mm:ss' ),1)
	data = []
	data1 = []
	dataAlarms = []
	header1 = ['Label','Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec']
	facilities = system.tag.readBlocking('[default]MQTT Facilities/Facilities')[0].value
	alarmProperties = ['eventTime',
	'label',
	'displayPath',
	'eventValue',
	'name',
	'Source']

	header = ['EventTime',
	'label',
	'DisplayPath',
	'eventValue',
	'State',
	'Source']
	count = 0
	count1 = 0
	for month in range(12):
		dataBuffer = []
		startDateAggre = system.date.addMonths(dateStart, month)
		endDateAggre = system.date.addMonths(startDateAggre, 1)
		alarmJournal = system.alarm.queryJournal(startDate = startDateAggre, endDate = endDateAggre)
		
		if len(alarmJournal) != 0:
			for alarm in alarmJournal:
				bufferData = []
				for prop in alarmProperties:
					propertyAlarm = alarm.get(prop)
					bufferData.append(propertyAlarm)
				data.append(bufferData)
			datasetFinal = system.dataset.toDataSet(header, data)
			dataAlarm = system.dataset.filterColumns(datasetFinal, [5])
			for row in range(dataAlarm.getRowCount()):
				dataLocation = str(dataAlarm.getValueAt(row,0))
				splitName = dataLocation.split('/')[1]
				splitName1 = splitName.split(':')[1]
				data1.append(splitName1)
			for location in range(facilities.getRowCount()):
				number = count
				label1 = facilities.getValueAt(location,0)
				x = label1.split('/')
				y = str(x[0])
				splitName = y.replace('Ground Water Reservoir - 1','GWR1')
				dataBuffer.append(y)
				count = count + 1
				for loc in dataBuffer:
					countList = [0,0,0,0,0,0,0,0,0,0,0,0]
					count1 += 1
					for i in range(len(data1)):
						if data1[i] == loc:
							countList[month] += 1
				dataAlarms.append([y] + countList)
	data['alarmFinal'] = system.dataset.toDataSet(header1, dataAlarms)

```

---

<div class="post-metadata">

**Author:** ![Dan\_Kevin\_Dagapioso](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Dan\_Kevin\_Dagapioso](https://forum.inductiveautomation.com/u/Dan_Kevin_Dagapioso)\
**Post date:** [August 25, 2023, 3:56am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/2 "2023-08-25T03:56:12Z")

</div>

@justinedwards.jle can you help me with this?

---

<div class="post-metadata">

**Author:** ![Dan\_Kevin\_Dagapioso](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Dan\_Kevin\_Dagapioso](https://forum.inductiveautomation.com/u/Dan_Kevin_Dagapioso)\
**Post date:** [August 25, 2023, 3:58am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/3 "2023-08-25T03:58:19Z")

</div>

@nminchin i saw you in one of the post here in forum with the same problem as me. Can you help me with this?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 25, 2023, 4:10am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/4 "2023-08-25T04:10:41Z")

</div>

The variable `data` is a list, but you are using a string instead of an integer for an index:

```auto
data['alarmFinal']

```

`'alarmFinal'` is not correct

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 25, 2023, 4:11am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/5 "2023-08-25T04:11:34Z")

</div>

What Justin said. You're treating the list as if it were a dictionary. You're also completely overwriting the `data` parameter that you're passing into the function without ever using it.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/6/c6ca27a76f11d3e23443cd6c2289e44002d3dd45.png)

* * *

Also, unrelated, this is overly convoluted and doesn't look like it will work (why are you trying to fix the date? is this for testing?)

```auto
dateStart = system.date.addYears(system.date.parse(system.date.format(currentDate,currentYear + "-12-22 08:00:00"),'yyyy-MM-dd HH:mm:ss'),-1)
	endDate = system.date.addYears(system.date.parse(system.date.format(dateStart,currentYear + "-12-22 08:00:00"),'yyyy-MM-dd HH:mm:ss' ),1)

```

Simply use:

```auto
dateStart = system.date.addYears(currentDate, -1) # subtracts 1 year from the current date
dateEnd = system.date.addYears(currentDate, 1) # adds 1 year to the current date

```

If you want to set the month and day to specific values for some reason, you can use:

```auto
dateStart.setDate(22)
dateStart.setMonth(12-1) # sets to December, days start at 1, months start at 0... stupid Java... :face_with_symbols_over_mouth:

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 25, 2023, 4:33am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/6 "2023-08-25T04:33:30Z")

</div>

It must be a dictionary when it's passed in because this line doesn't bomb out:

```auto
currentYear = data['year']

```

It looks like this should be rewritten:

```auto
data = []
if len(alarmJournal) != 0:
	for alarm in alarmJournal:
		bufferData = []
		for prop in alarmProperties:
			propertyAlarm = alarm.get(prop)
			bufferData.append(propertyAlarm)
		data.append(bufferData)
	datasetFinal = system.dataset.toDataSet(header, data)

```

Change it to this, and see if that fixes the problem:

```auto
if alarmJournal:
	bufferedData = [[alarm.get(prop) for prop in alarmProperties] for alarm in alarmJournal]
	datasetFinal = system.dataset.toDataSet(header, bufferedData)

```

This simplifies the code with list comprehension and eliminates the need for two variables in your list of buffered lists. Consequently, you can use the variable bufferedData for your dataset data and not overwrite your dictionary.

---

<div class="post-metadata">

**Author:** ![Dan\_Kevin\_Dagapioso](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Dan\_Kevin\_Dagapioso](https://forum.inductiveautomation.com/u/Dan_Kevin_Dagapioso)\
**Post date:** [August 25, 2023, 5:20am UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/7 "2023-08-25T05:20:21Z")

</div>

Thanks! It works!

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [October 10, 2025, 6:58pm UTC](https://forum.inductiveautomation.com/t/reporting-tag-historian-query-error/78369/8 "2025-10-10T18:58:52Z")

</div>

What was the actual issue here?

I’ve got the same error and I don’t understand why. I’ve created a valid dataset and it looks correct when printed. This is what the script looks like when a brand new script data source is created:

```python
def updateData(data, sample):
	data['myKey']='Example'

```

So, why does

```python
def updateData(data, sample):
	.
	.
	.
	data['data'] = dataset

```

results in the “list indices must be integers” error?

I am not assigning or overwriting `data` until the very last line.

Nevermind… the default `system.dataset.toDataset(headers, data)` was my issue. I had reassigned `data` to be used in that call. I need a unique name for the function, otherwise it just overwrites.
