# Adding pens to ad-hoc to a trend - Missing exposure to functions needed

**URL:** <https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432>\
**Category:** Ignition\
**Created:** [June 27, 2024, 2:25am UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432 "2024-06-27T02:25:55Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [June 27, 2024, 2:25am UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/1 "2024-06-27T02:25:55Z")

</div>

I'm adding the ability to add pens to a popup trend ad-hoc from an overview page, but noticed that there are critical functions missing from the `shared` library in order to actually do this properly.

To add a pen to a chart, you need:

- ✅ history provider
- ❌ tag provider
- ❌ tag provider gateway name
- ✅ tag path

Before you say that you can just read the tag provider from the tag and the gateway name from the [system] tags, you can't do this in a multi-gateway network. Remote tag provider names are not guaranteed to be the same as the name on the original gateway, and gateway name is just not available to retrieve at all, using off the shelf methods.

So we need methods to get the tag provider name and gateway that the tag provider exists on.

As a work around, i'm going down the rabbit hole of unsupported API methods to do this...

---

<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:** [June 27, 2024, 3:05am UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/2 "2024-06-27T03:05:02Z")

</div>

E.g. using a super dodgy query on the internal db...

```python
tagPath = 'Tag/Path'
# get the tag provider in the local gateway from the config in case the tag provider wasn't provided in the path
tagProvider = system.tag.getConfiguration(tagPath)[0]['path'].split(']')[-1]

context = system.util.getContext()
session = context.getPersistenceInterface().getSession()
try:
	query = """
	SELECT
		COALESCE(gtps.PROVIDERNAME, tps.NAME) as tag_provider,
		gtps.HISTORYDRIVERNAME as gateway_name
	
	FROM
		TAGPROVIDERSETTINGS tps
		LEFT JOIN GANTAGPROVIDERSETTINGS gtps ON gtps.PROFILEID = tps.TAGPROVIDERSETTINGS_ID
	
	WHERE tps.name = '{}'
	""".format(tagProvider)
	rt = session.rawQueryMaps(query, True, []) # sql, flush, params
finally:
	session.close()

rt = rt[0]
histProvider, gatewayName = [qval.value for qval in system.tag.readBlocking([
	'{}.historyProvider'.format(tagPath),
	'[System]Gateway/SystemName'])]
gatewayName = gatewayName or rt['gateway_name']
tagProvider = rt['tag_provider']
tagPath = tagPath.split(']')[-1]

system.perspective.print('histProvider: {}'.format(histProvider))
system.perspective.print('gatewayName: {}'.format(gatewayName))
system.perspective.print('tagProvider: {}'.format(tagProvider))
system.perspective.print('tagPath: {}'.format(tagPath))

```

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [August 12, 2024, 7:35pm UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/3 "2024-08-12T19:35:11Z")

</div>

What display component are you using? Within Perspective, both the PowerChart and TimeSeriesChart permit passing the [full]tag/path to the view. This has been useful, because it allows Ignition's Realtime Tag Provider Settings to determine where to grab the historical data from (via a database query, or from the remote gateway). So, the same view can be used on a full Ignition gateway (querying database) as on the Edge gateway (used as a local HMI, where it queries internal SQLite).

As an aside... I agree that there should be a more straightforward way to get data from the internal db. 'Hosing' of the gateway is possible, if not likely, using the method you outlined above... but I still do it.

---

<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:** [March 24, 2026, 3:33am UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/4 "2026-03-24T03:33:55Z")

</div>

I finally tried this and you’re right, the `pens[x].data.source` can just be set to `[tagProvider]tagPath` instead of the full history tag path `histprov:blah blah` which I thought was the only way, and I couldn’t get it to work with just provider and tagpath. Thanks! (only took me 2 years to try it…)

---

<div class="post-metadata">

**Author:** ![hunterdg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hunterdg/32/67774_2.png) [@hunterdg](https://forum.inductiveautomation.com/u/hunterdg)\
**Post date:** [April 24, 2026, 5:54am UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/5 "2026-04-24T05:54:59Z")

</div>

seems to only work with local providers for me? (8.1.48)

also this "switch"doesn't appear to be happening: [Ignition Perspective Powerchart tag path is not returning the correct case - #3 by jeffrey.boey](https://forum.inductiveautomation.com/t/ignition-perspective-powerchart-tag-path-is-not-returning-the-correct-case/56363/3)

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [April 24, 2026, 12:43pm UTC](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432/6 "2026-04-24T12:43:35Z")

</div>

The [provider]tag/path method should also work for remote providers, but requires that you have the remote tag provider settings configured correctly for your desired historian.
