# Force all tags with History enabled to log a value

**URL:** <https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [August 9, 2024, 10:04pm UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451 "2024-08-09T22:04:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [August 9, 2024, 10:04pm UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451/1 "2024-08-09T22:04:28Z")

</div>

I need to compare the values coming out of the new Ignition system and an existing system.

I have a button setup trying to use system.tag.storeTagHistory but I keep getting different errors. Just wondering if this is something you can even do?

Current error:  
Error forwarding data  
java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from UNKNOWN to VARCHAR is unsupported.

```python
def runAction(self, event):
	# Enable print to Ignition logger.
	logger = system.util.getLogger("API_POST_Logger")
	
	#parentPath = self.parent.parent.getChild("FlexContainer_Hist_Tag_Path").getChild("TextField").props.text
	parentPath = "[default]07"
	logger.info(parentPath)
	
	# Get a list of all tags in the system
	results = system.tag.browseTags(parentPath=parentPath, recursive=True)
	
	# Prepare lists for tag paths and values
	tagPaths = []
	values = []
	
	# Iterate through the results to get tag paths and current values
	for result in results:
		tagPath = result.fullPath
		currentValue = system.tag.readBlocking([tagPath])[0].value
		
		tagPaths.append(tagPath)
		values.append(currentValue)
		
	# Store the current values in the historian
	system.tag.storeTagHistory(historyprovider="MSSQLServer", tagProvider="[default]", Paths=tagPaths, values=values)
	
	# Log success
	logger.info("Successfully stored current values to historian for tags: " + str(tagPaths))

```

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [August 9, 2024, 11:22pm UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451/2 "2024-08-09T23:22:53Z")

</div>

Your code looks like you're logging all tags, not just tags with history, but I think your tagProvider should just be "default" without the brackets when calling storeTagHistory.

Also, you'd be better off running your for loop like this to get all the tag paths first, then reading them all at once:

```python
provider = 'default'

query = {
  "options": {
    "includeUdtMembers": True,
    "includeUdtDefinitions": False
  },
  "condition": {
    "attributes": {
      "values": [
        "history"
      ],
      "requireAll": True
    }
  },
  "returnProperties": [
    "tagType",
    "quality"
  ]
}

results = system.tag.query(provider, query)

for result in results:
	tagPaths.append(result['fullPath'])

values = [tag.value for tag in system.tag.readBlocking(tagPaths)]
system.tag.storeTagHistory(historyprovider="MSSQLServer", tagprovider=provider, paths=tagPaths, values=values)

```

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [August 10, 2024, 12:17am UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451/3 "2024-08-10T00:17:23Z")

</div>

Thanks, I get all the "defaults" confused. Even when I'm using the correct one sometimes you need it in the path and sometimes you don't and so on.

I had been trying a few things and the `tagType` was left out of my posted example. Not sure if it is working, I'm wanting to find only the Expression tags and that is one that is not listed in the manual. If I try something that I know should not work it gives an error about that `tagType` not being correct but it seems to be ok with "Expression" as the type.

_Possible values are OPC, MEMORY, DB, QUERY, Folder, DERIVED and UDT\_INST._

I no longer get the error after removing the brackets. `tagProvider="default"`

Now I just need to see if it did what I need.

Also need to see where the heck this other "default" came from. I know how to get rid of old tags that still show up in the tag browse but no idea how I managed this one with the brackets.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/ebea996aa5229c48145fbb9711e5ce8ae4b0905f.png)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [August 10, 2024, 12:58am UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451/4 "2024-08-10T00:58:52Z")

</div>

Use the tag report tool to build out the query as needed and copy the query as JSON and use it in place of what I put. It will work better than the browse function you're currently using.

> **[Tag Report Tool | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/tag-report-tool)**
>
> The Tag Report Tool allows users to search for tags by multiple criteria, including Tag Path, Quality, Type, Traits, and values on specific Properties.

---

<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 10, 2024, 2:18am UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451/5 "2024-08-10T02:18:02Z")

</div>

> [@michael.flagler](#):
>
> `values = [tag.value for tag in system.tag.readBlocking(tagPaths)]`

Pedant fix:  
`values = [qval.value for qval in system.tag.readBlocking(tagPaths)]`

However, the tag report function can also return values, so I'd use them instead of reading them if you care about code speed (looks like this is a once off though, so 🤷‍♂️ )

---

<div class="post-metadata">

**Author:** ![r123](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@r123](https://forum.inductiveautomation.com/u/r123)\
**Post date:** [August 10, 2024, 3:11am UTC](https://forum.inductiveautomation.com/t/force-all-tags-with-history-enabled-to-log-a-value/94451/6 "2024-08-10T03:11:17Z")

</div>

I wanted to get the values into the historian so the same tools can write the values out to the Azure database and they are processed the same as normal. Then I can compare to a dump from the old system from the same time.

It is just a one (or two) off and it runs really fast as is.

Anyone know where the extra bracketed object in the tab browser came from or how to get rid of if?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/ebea996aa5229c48145fbb9711e5ce8ae4b0905f.png)
