# Gateway Script Writing to Tag

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-writing-to-tag/24547>\
**Category:** Ignition\
**Created:** [May 1, 2019, 8:44am UTC](https://forum.inductiveautomation.com/t/gateway-script-writing-to-tag/24547 "2019-05-01T08:44:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.shan](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@a.shan](https://forum.inductiveautomation.com/u/a.shan)\
**Post date:** [May 1, 2019, 8:44am UTC](https://forum.inductiveautomation.com/t/gateway-script-writing-to-tag/24547/1 "2019-05-01T08:44:46Z")

</div>

Hi All,

I’m having an issue writing the value returned by a runNamedQuery to a tag,  
if I replace “value” or “value1” with an integer it writes to the tag no problem,  
Hoping someone can see something obvious,

CurrentBatchID = system.tag.read("[default]BatchID 1/BatchID").value  
PrevBatchID = system.tag.read("[default]BatchID 1/PreviousBatchID").value  
if CurrentBatchID == PrevBatchID:  
value = system.db.runNamedQuery(“Test”,“Subtract Parts Made”, {})  
system.tag.write("[default]BatchID 1/New Tag",“value”)  
else:  
value1 = system.db.runNamedQuery(“Test”, “Select Parts Made”, {})  
system.tag.write("[default]BatchID 1/New Tag.value",“value1”)

My named queries are as follows;  
Select Parts Made - SELECT TOP 1 Parts\_Made FROM Actual\_Made ORDER BY t\_stamp desc;

Subtract Parts Made - SELECT T2.Parts\_Made - T1.Parts\_Made AS Parts\_Made, T1.t\_stamp AS t\_stamp  
FROM Actual\_Made T1  
JOIN Actual\_Made T2 ON T1.[t\_stamp] \< T2.[t\_stamp]  
ORDER BY [t\_stamp] desc;

Each work correctly when tested,  
Any tips would be appreciated,

Thanks

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 1, 2019, 11:08am UTC](https://forum.inductiveautomation.com/t/gateway-script-writing-to-tag/24547/2 "2019-05-01T11:08:26Z")

</div>

As your script is now you’re writing String values of “value1” and “value2”. Remove the quotes to use the value from your query.

---

<div class="post-metadata">

**Author:** ![a.shan](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@a.shan](https://forum.inductiveautomation.com/u/a.shan)\
**Post date:** [May 1, 2019, 11:22am UTC](https://forum.inductiveautomation.com/t/gateway-script-writing-to-tag/24547/3 "2019-05-01T11:22:47Z")

</div>

Thanks very much that worked 👍
