# Send tags to Agent Gateway from script

**URL:** <https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [October 3, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761 "2024-10-03T09:18:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [October 3, 2024, 9:18am UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761/1 "2024-10-03T09:18:10Z")

</div>

Hello,

I want to send tags from my controller to Agent when after a button clique.

I am trying to use the SDK, but i got an error.

Here is my code:

```python
def runAction(self, event):
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	from com.inductiveautomation.ignition.gateway.tasks import ScheduleMode
	from com.inductiveautomation.ignition.gateway.tasks import TaskSettings
	from com.inductiveautomation.ignition.gateway.tasks import GatewayTaskRecord

	gatewayContext = IgnitionGateway.get()
	taskManager = gatewayContext.getTaskManager()
	
	settings = taskManager.createNewTask("eam", "sendTags")

	record = settings.getTaskRecord()
	record.setName("Send KPI To Agent")
	record.setOwnerId("eam")
	record.setMode(ScheduleMode.OnDemand) 
	record.setTaskId("sendTags")
	record.setSchedule("ondemand")
	record.setFailData("overwrite")

	settingsRecord = settings.getTaskSettingsRecord()

	meta = settingsRecord.getMeta()

	settingsRecord.setString(meta.getField("targetGateways"), "Ignition-VM")
	settingsRecord.setString(meta.getField("targetTagProvider"), "edge")
	settingsRecord.setString(meta.getField("tagPaths"), "[default]test,")
	settingsRecord.setBoolean(meta.getField("controllerIsTarget"), False)
	settingsRecord.setString(meta.getField("collisionPolicy"), "overwrite")

	settings.save()

```

And the error i got is:

```python
	Error running action 'component.onActionPerformed' on Pages/machine/settings/KPIs/addKPIForm@P-KEOuB09/root/submitRow/submit: Traceback (most recent call last): File "<function:runAction>", line 51, in runAction at simpleorm.sessionjdbc.SSessionJdbcHelper.flushExecuteUpdate(SSessionJdbcHelper.java:422) at simpleorm.sessionjdbc.SSessionJdbcHelper.flush(SSessionJdbcHelper.java:389) at simpleorm.sessionjdbc.SSessionJdbc.flush(SSessionJdbc.java:459) at simpleorm.sessionjdbc.SSessionJdbc.flush(SSessionJdbc.java:443) at simpleorm.sessionjdbc.SSessionJdbc.commitAndDetachDataSet(SSessionJdbc.java:382) at com.inductiveautomation.ignition.gateway.localdb.PersistenceInterfaceImpl.save(PersistenceInterfaceImpl.java:107) at com.inductiveautomation.ignition.gateway.tasks.TaskSettings.save(TaskSettings.java:69) at jdk.internal.reflect.GeneratedMethodAccessor391.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) simpleorm.utils.SException$Jdbc: simpleorm.utils.SException$Jdbc: Executing INSERT INTO gatewaytaskrecord (gatewaytaskrecord_ID, name, ownerid, taskid, mode, schedule, faildata) VALUES (?, ?, ?, ?, ?, ?, ?) for [GatewayTaskRecord 34 NewRecord Dirty0]

```

Can anyone help me ?

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [October 3, 2024, 11:25am UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761/2 "2024-10-03T11:25:55Z")

</div>

@paul-griffith Do you have any idea ?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 3, 2024, 1:11pm UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761/3 "2024-10-03T13:11:06Z")

</div>

Nope. You're doing something totally unsupported.

Why don't you just use system.util.sendMessage across the gateway network and call system.tag.configure locally on the receiver gateway message handler?

---

<div class="post-metadata">

**Author:** ![e.sagnelonge](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@e.sagnelonge](https://forum.inductiveautomation.com/u/e.sagnelonge)\
**Post date:** [October 3, 2024, 3:46pm UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761/4 "2024-10-03T15:46:37Z")

</div>

Here is a slightly simpler approach.  
The code below retrieves the `EAMGatewayHook` from the gateway context (`IgnitionGateway`).  
Once the hook is available, we get the RPC that handles the tag transmission for us.

You just need to fill in the fields of the `initSendTags` method with appropriate values of the correct data type.

I didn't go all the way through, but it should work quite easily.

```python
def sendTags():
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	context = IgnitionGateway.get()
	moduleManager = context.getModuleManager()
	EAMGatewayHook = moduleManager.getModule("com.inductiveautomation.eam").getHook()
	rpc = EAMGatewayHook.getRPCHandler(None, None)
	
	rpc.initSendTags(targetProvider, agentServerIds, tags, saveTask, targetController)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f577e17096eb6a961a634289ff9a9858d301fd8b.png)

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [October 7, 2024, 8:31am UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761/5 "2024-10-07T08:31:25Z")

</div>

Thank you @e.sagnelonge.

Yes, this method is working, i added two lines of code:

```python
def sendTags():
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser

	context = IgnitionGateway.get()
	moduleManager = context.getModuleManager()
	EAMGatewayHook = moduleManager.getModule("com.inductiveautomation.eam").getHook()
	rpc = EAMGatewayHook.getRPCHandler(None, None)

	path = TagPathParser.parse("[default]test")

	rpc.initSendTags("edge", ["edge-HOST-NAME"], [path], True, False, "Overwrite") # After version 8.1.39 it is mandatory to add a sixth argument "Overwrite, Abort..."

```

---

<div class="post-metadata">

**Author:** ![Mehdi\_MECHEDAL](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mehdi\_MECHEDAL](https://forum.inductiveautomation.com/u/Mehdi_MECHEDAL)\
**Post date:** [October 7, 2024, 8:32am UTC](https://forum.inductiveautomation.com/t/send-tags-to-agent-gateway-from-script/96761/6 "2024-10-07T08:32:31Z")

</div>

@paul-griffith, yes this solution also works.
