# Gateway Tag Change Script help (probably syntax)

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-help-probably-syntax/71766>\
**Category:** Ignition\
**Tags:** perspective, ignition81, scripting\
**Created:** [March 29, 2023, 12:08pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-help-probably-syntax/71766 "2023-03-29T12:08:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cameronin](https://avatars.discourse-cdn.com/v4/letter/c/9fc29f/32.png) [@Cameronin](https://forum.inductiveautomation.com/u/Cameronin)\
**Post date:** [March 29, 2023, 12:08pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-help-probably-syntax/71766/1 "2023-03-29T12:08:43Z")

</div>

I'm trying to use a gateway tag change script to get a value change in a tank (with corresponding start and end times) so I can get flow in to the tank from two historicised flow meters (using tagHistoryQuery), and calculate outflow (there isn't a meter on the outflow because Reasons).

The tank and inflow tags are OPC.  
The outflow I'm trying to write to is a memory tag set to 'float'.

Script that is Just Not Working At All:

```auto
if not initialChange:
	damTot = "[default]OPCTag1"
	ufTot = "[default]OPCTag2"
	paths = [damTot,ufTot]
	
	oldLvl = previousValue.getValue()
	newLvl = newValue.getValue()
	startT = previousValue.getTimestamp()
	endT = newValue.getTimestamp()
	
	inData = system.tag.queryTagCalculations(paths, "Range", startT, EndT)
	inFlow = inData.getValueAt(0,1)+inData.getValueAt(1,1)
	outFlow = oldLvl+inFlow-newLvl
	
	system.tag.writeBlocking(["[default]MemoryTag"], outFlow)

```

I've tried using event.getCurrentValue().getValue() and event.getPreviousValue().getValue() instead of previousValue.getValue() and newValue.getValue();  
I've tried previousValue().getValue() and newValue().getValue();  
I've tried calling a project script:

```auto
if not initialChange:
	
	oldLvl = previousValue.getValue()
	newLvl = newValue.getValue()
	startT = previousValue.getTimestamp()
	endT = newValue.getTimestamp()
	
	payload = {"oldLvl":oldLvl, "newLvl":newLvl, "startT":startT, "endT":endT}
	
	outFlow = runTest.cwtOut(oldLvl, newLvl, startT, endT)

```

with the path allocation, tag calcs and writeBlocking in the project script.  
But it just seems to not work at all.  
All I get in the gateway log is "Error executing tag change script: Project/ScriptName"

I am at a loss what to do to fix it...  
help please?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 29, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-help-probably-syntax/71766/2 "2023-03-29T13:42:49Z")

</div>

There should be more error info on the gateway, did you expand the error message? Next, I would add a logger to see if the values are what you expect.

```auto
logger = system.util.getLogger('inflowScript')
logger.info(str(oldLvl))
...

```

These messages will show up in the gateway logs. Another thing to try is to change your tag calculation to this.

```auto
inData = system.tag.queryTagCalculations(paths, ["Range"], startDate=startT, endDate=EndT)

```

---

<div class="post-metadata">

**Author:** ![Cameronin](https://avatars.discourse-cdn.com/v4/letter/c/9fc29f/32.png) [@Cameronin](https://forum.inductiveautomation.com/u/Cameronin)\
**Post date:** [March 29, 2023, 1:47pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-help-probably-syntax/71766/3 "2023-03-29T13:47:13Z")

</div>

@dkhayes117  
There is not more error info on the gateway as far as I can tell. That's the whole error message, and there isn't a little "+" to click on or anything.

I'll try the tag calculation you suggest 🙂  
Thanks
