# Using a script to enable tag history and setting the database

**URL:** <https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 16, 2025, 8:33pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445 "2025-06-16T20:33:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfaith](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@tfaith](https://forum.inductiveautomation.com/u/tfaith)\
**Post date:** [June 16, 2025, 8:33pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/1 "2025-06-16T20:33:02Z")

</div>

I am trying to save time by running a script to change tags by enabling history and set a database. I am unable to figure out how to set the database.

```python
def enable_history_for_folder(base_path):
    tags = system.tag.browse(base_path)
    database = "SFISQL04_MSSQL"
    for tag in tags:
        full_path = base_path + "/" + tag['name']
        
        if tag['hasChildren']:
            # Recurse into subfolders
            enable_history_for_folder(full_path)
        else:
            try:
                # Get tag configuration
                config = system.tag.getConfiguration(full_path, True)[0]

                # Set history properties
                config["HistoryEnabled"] = True
                config["StorageProvider"] = database # Replace with your actual history provider name

                # Write the new config
                system.tag.configure(base_path, [config], "m")

                print("Enabled history for:", full_path)
            except Exception as e:
                print("Failed to update:", full_path, "| Error:", e)

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 16, 2025, 8:57pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/2 "2025-06-16T20:57:18Z")

</div>

Post code, not pictures of code, it helps others while troubleshooting. Please see [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831). You can edit your post by clicking the pencil icon in the lower right.

Have you confirmed that the rest of your changes are being applied? Or is the script failing entirely? Have you confirmed that the history provider that you are specifying actually exists as a history provider in your gateway?

---

<div class="post-metadata">

**Author:** ![tfaith](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@tfaith](https://forum.inductiveautomation.com/u/tfaith)\
**Post date:** [June 16, 2025, 9:03pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/3 "2025-06-16T21:03:24Z")

</div>

I updated my post. Yes, it is just the storage provider update that is not working. It will change the history enabled from false to true.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 16, 2025, 9:08pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/4 "2025-06-16T21:08:02Z")

</div>

In that case I would double check that the history provider you are specifying actually exists. The `Tags` section in the `Status` tab of your gateway should show a list of your history providers. Also, confirm you are setting the correct key in the tag config.

If you can, manually set the provider you want on a single tag, then read that tag via `system.tag.getConfiguration` to see how the provider is shown in the tag config.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2025, 9:10pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/5 "2025-06-16T21:10:33Z")

</div>

> [@tfaith](#):
>
> Yes, it is just the storage provider update that is not working.

Because the property you are trying to update is actually called `"HistoryProvider"`

---

<div class="post-metadata">

**Author:** ![tfaith](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@tfaith](https://forum.inductiveautomation.com/u/tfaith)\
**Post date:** [June 16, 2025, 9:11pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/6 "2025-06-16T21:11:47Z")

</div>

Thank you for the help

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [June 16, 2025, 9:12pm UTC](https://forum.inductiveautomation.com/t/using-a-script-to-enable-tag-history-and-setting-the-database/107445/7 "2025-06-16T21:12:08Z")

</div>

For future scripting:

> **[Tag Properties | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/tags/tag-properties#history-properties)**
>
> Tags are points of data and may have static values or dynamic values that come from an OPC address, an Expression, or a SQL query. The values can be used on screens and in Transaction Groups. Additionally, tags offer a core set of features above and...
