# Gateway Tag Change Script or Local Tag Change Script

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-or-local-tag-change-script/100275>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 27, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-or-local-tag-change-script/100275 "2024-12-27T18:54:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Thompson](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robert\_Thompson](https://forum.inductiveautomation.com/u/Robert_Thompson)\
**Post date:** [December 27, 2024, 6:54pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-or-local-tag-change-script/100275/1 "2024-12-27T18:54:23Z")

</div>

Is there any difference between the Gateway Event, Tag Change and the Script function on a tag for value change? I see the Gateway Event can be configured for several items including tag change. I'm just wondering if I should make the script a gateway event or leave it a local tag change. The problem I see is the tag remains on and the tag will not run a second time.

```python

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	trigger=system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/GetPLC912Data.value")
	trigger=trigger[0].value
	if trigger == 1:
		recname = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Recipe_Name.value")
		recname=recname[0].value
		EndDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/StopTime.value")
		EndDate=EndDate[0].value
		recipe = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Recipe_Number.value")
		recipe=recipe[0].value
		skid = 912
		StartDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/StartTime.value")
		StartDate=StartDate[0].value
		unit = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Unit_Number.value")
		unit=unit[0].value
		params={"EndDate":EndDate,"Recipe":recipe,"RecipeName":recname,"Skid":skid,"StartDate":StartDate,"Unit":unit}
		ret=system.db.runNamedQuery("NXM_OEE","CIP/CIPInsert", params)
		PK=system.db.runNamedQuery("NXM_OEE","CIP/CIPGetPK")
		x=0
		for x in range(38):
			cond = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Conductivity_SP.value")
			cond=cond[0].value
			pumpsp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Pump_SP.value")
			pumpsp=pumpsp[0].value
			EndDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/Step"+str(x)+"/StopTime.value")
			EndDate=EndDate[0].value
			StartDate = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Times_Input_912/Step"+str(x)+"/StartTime.value")
			StartDate=StartDate[0].value
			stepname = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Step_Name.value")
			stepname=stepname[0].value		
			stepnum = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Step_Number.value")
			stepnum=stepnum[0].value		
			steptimesp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Step_Time_SP.value")
			steptimesp=steptimesp[0].value
			suptimesp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Supervision_Step_Time_SP.value")
			suptimesp=suptimesp[0].value
			tempsp = system.tag.readBlocking("[New Castle]NXN-HHC CIP/912_CIP/CIP_Report_Data_Input_912/Step"+str(x)+"/Temperature_SP.value")
			tempsp=tempsp[0].value
			params={"EndDate":EndDate,"PK":PK,"PumpSP":pumpsp,"StepName":stepname,"StepNum":stepnum,"StartDate":StartDate,"SVTimeSP":suptimesp,"TempSP":tempsp,"TimeSP":steptimesp,"CondSP":cond}
			if (EndDate <> "0002-11-30 00:00:00" and stepname <> ""):
				ret=system.db.runNamedQuery("NXM_OEE","CIP/CIPStepInsert", params)
	system.tag.writeBlocking("[New Castle]NXN-HHC CIP/912_CIP/GetPLC912Data.value",[False])

```

Here is the script for reference. The script runs when GetPLC912Data goes positive. Thank you for any comments.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 27, 2024, 8:29pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-or-local-tag-change-script/100275/2 "2024-12-27T20:29:57Z")

</div>

> [@Robert\_Thompson](#):
>
> any difference

Oh, yes. Your script is very much unsuitable for definition on the tag itself. Some reading and further links:

> [@PLC to Ignition Interactions](https://forum.inductiveautomation.com/t/plc-to-ignition-interactions/99896/5):
>
> There are pros and cons. (Numerous discussions here on those.) But it is almost always preferable to system.util.invokeAsynchronous(). Starting new threads is a performance killer, and can run wild if you aren't careful. Discussions like these (and more, if you tweak the search terms): [https://forum.inductiveautomation.com/search?q=gateway%20tag%20change%20event%20valueChange%20thread%20pool%20order%3Alatest](https://forum.inductiveautomation.com/search?q=gateway%20tag%20change%20event%20valueChange%20thread%20pool%20order%3Alatest) If you have a particular need for valueChange scripting, but also need to not bloc…

---

<div class="post-metadata">

**Author:** ![Robert\_Thompson](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Robert\_Thompson](https://forum.inductiveautomation.com/u/Robert_Thompson)\
**Post date:** [December 27, 2024, 8:45pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-or-local-tag-change-script/100275/3 "2024-12-27T20:45:17Z")

</div>

Thank you. I found some discussions about when to use a gateway script. I changed the script to a gateway function today. Thank you for the reply. Have a great weekend!
