# How to write to a table component using system.tag.queryTagHistory?

**URL:** <https://forum.inductiveautomation.com/t/how-to-write-to-a-table-component-using-system-tag-querytaghistory/33692>\
**Category:** Ignition\
**Created:** [April 5, 2020, 3:07pm UTC](https://forum.inductiveautomation.com/t/how-to-write-to-a-table-component-using-system-tag-querytaghistory/33692 "2020-04-05T15:07:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [April 5, 2020, 3:07pm UTC](https://forum.inductiveautomation.com/t/how-to-write-to-a-table-component-using-system-tag-querytaghistory/33692/1 "2020-04-05T15:07:15Z")

</div>

Good morning, my name is Felipe and I have been studying ignition hard, but I am still very young on the platform. I have been studying a way to write in a table component by clicking on the mouse using the `system.tag.queryTagHistory` function, I don’t know is possible, and if so, I would like to know what I’m doing wrong? used as reference in startdate the following expression in a text field component:

```auto
dateArithmetic({Setup_Plant/Plant01/CurrentShiftStart1},-1, 'days')

```

the enddate reference I used the following expression in the text field 1 component:

`dateArithmetic({Setup_Plant/Plant01/CurrentShiftStart1},0, 'days')`

and in the button component scripting component, in the event handlers \>\> mouse clicked I used the expression:

```auto
startdate =event.source.parent.getComponent('Text Field').text
enddate = event.source.parent.getComponent('Text Field 1').text
	
pathlist = []
namelist = ["TimeStamp"]
name = "necker0101"
historyTagPath = "[ign_Historical]Machines_DM/" + name + "/count_discharge"
pathlist.append(historyTagPath)
infeedName = name + "_discharge"
namelist.append(infeedName)	
#	name = "necker0201"
#	historyTagPath = "[ign_Historical]Machines_DM/" + name + "/count_discharge"
#	pathlist.append(historyTagPath)
#	infeedName = name + "_discharge"
#	namelist.append(infeedName)				
data['hourly_counts'] = system.tag.queryTagHistory(paths=pathlist, aggregationMode='Sum', columnNames=namelist, startDate=startdate, endDate=enddate, intervalHours=1, noInterpolation=True)
data['hourly_counts'] = event.source.parent.getComponent('Table').data

```

I really don’t know if it’s possible, I’m just testing it for another application and also to improve my knowledge in other scripting functions. because I believe you could do this using the `system.dataset.toDataSet`

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/687d92ef3a9684ac96356a78a75f6caf2dcbd06b.png)

---

<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:** [April 6, 2020, 5:55pm UTC](https://forum.inductiveautomation.com/t/how-to-write-to-a-table-component-using-system-tag-querytaghistory/33692/2 "2020-04-06T17:55:21Z")

</div>

The “data[‘hourly\_counts’]” looks like how you would create a dataset in a report. Scripting on a vision screen is different. Assuming what you wrote through your queryTagHistory function is right then you just need to change the bottom two lines to write it into your table. This is also assuming your component name is ‘Table’.

```auto
hourly_counts = system.tag.queryTagHistory(paths=pathlist, aggregationMode='Sum', columnNames=namelist, startDate=startdate, endDate=enddate, intervalHours=1, noInterpolation=True)
event.source.parent.getComponent('Table').data = hourly_counts

```

You can also do:

```auto
event.source.parent.getComponent('Table').data = system.tag.queryTagHistory(paths=pathlist, aggregationMode='Sum', columnNames=namelist, startDate=startdate, endDate=enddate, intervalHours=1, noInterpolation=True)

```

The system.tag.queryTagHistory should return a dataset so you don’t need to convert it to one.

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [April 6, 2020, 10:58pm UTC](https://forum.inductiveautomation.com/t/how-to-write-to-a-table-component-using-system-tag-querytaghistory/33692/3 "2020-04-06T22:58:58Z")

</div>

worked perfectly.

thank you very much
