# queryHistory usage

**URL:** <https://forum.inductiveautomation.com/t/queryhistory-usage/21269>\
**Category:** Module Development\
**Created:** [December 6, 2018, 8:54pm UTC](https://forum.inductiveautomation.com/t/queryhistory-usage/21269 "2018-12-06T20:54:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [December 6, 2018, 8:54pm UTC](https://forum.inductiveautomation.com/t/queryhistory-usage/21269/1 "2018-12-06T20:54:00Z")

</div>

I try to query History from gateway scope with :  
context.getTagManager(). **queryHistory** (tagHistoryQueryParams, streamingDatasetWriter);

tagHistoryQueryParams.setPaths(); is used to provide tagPaths.  
In the BasicTagPath, do we need to provide the history provider in the source ?  
In this case what is the form/synthax to use ?

Probably the tag provider is enough, the history provider is resolved with it.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [December 7, 2018, 10:06am UTC](https://forum.inductiveautomation.com/t/queryhistory-usage/21269/2 "2018-12-07T10:06:14Z")

</div>

@paul-griffith  
I try to create a **BasicTagHistoryQueryParams** , but I’m looking for an example for those settings :

```auto
tagHistoryQueryParams.setAggregationMode();
tagHistoryQueryParams.setAliases();
tagHistoryQueryParams.setColumnAggregationModes();
tagHistoryQueryParams.setEndDate()
tagHistoryQueryParams.setStartDate();
tagHistoryQueryParams.setQueryFlags();
tagHistoryQueryParams.setReturnFormat();
tagHistoryQueryParams.setReturnSize();
```

With only the following :

```auto
(startDate => now + 1 days
endDate => now - 2 days)

tagHistoryQueryParams.setEndDate(startDate);
tagHistoryQueryParams.setStartDate(endDate);
tagHistoryQueryParams.setReturnFormat(ReturnFormat.Tall);
Flags flags = Flags.createFromValue(TagHistoryQueryFlags.BOUNDING_VALUES_YES);
flags.and(TagHistoryQueryFlags.NO_INTERPOLATION);
flags.and(TagHistoryQueryFlags.NO_SCANCLASS_VALIDATION);

context.getTagManager().queryHistory(tagHistoryQueryParams, streamingDatasetWriter);
```

return only the **last value** for the specified tag ???  
I need to collect all the **raw history values** …

streamingDatasetWriter.getRowCount() = 1

histo.sqlt\_data\_1\_2018\_12 for the tag contain 3 values :

```auto
29	5 192	1544173333405	2018-12-07 10:02:13.4050
29	10 192	1544173335803	2018-12-07 10:02:15.8030
29	50 192	1544194325530	2018-12-07 15:52:05.5300
```

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [December 7, 2018, 6:59pm UTC](https://forum.inductiveautomation.com/t/queryhistory-usage/21269/3 "2018-12-07T18:59:21Z")

</div>

I found what was wrong

To obtain all tags changes, it is necessary to add :

```auto
tagHistoryQueryParams.setReturnSize(-1);
```

In the script function system.tag.queryHistory, returnsize has a -1 as parameter default value 😉
