# 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:** 1\
**Showing post:** 2

<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))

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/adding-pens-to-ad-hoc-to-a-trend-missing-exposure-to-functions-needed/92432)._
