# Script oneshot

**URL:** <https://forum.inductiveautomation.com/t/script-oneshot/13968>\
**Category:** Ignition\
**Created:** [March 31, 2017, 8:11pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968 "2017-03-31T20:11:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [March 31, 2017, 8:11pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/1 "2017-03-31T20:11:08Z")

</div>

I have a timer on a screen. Within this timer there is a script running every cycle (actionPerformed). The script is looking at a tag on the server, and if this value == 4 then a section of the script needs to run just one time. (ONESHOT).

I’m setting a value at the end of this section to indicate that the section has run, but it takes a while for the tag to update with the new value and for me to read it on a subsequent scan. Is there a better way of handling how to “oneshot” some logic in the script language?

---

<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:** [March 31, 2017, 8:17pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/2 "2017-03-31T20:17:51Z")

</div>

If you need this to be one time globally, you’ll need to implement the timer and scripting in the gateway, not on a screen. Otherwise, you can use the newValue & oldValue properties of a propertyChange event to determine if your conditions are met.

---

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [March 31, 2017, 8:31pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/3 "2017-03-31T20:31:31Z")

</div>

not global, so a timer on the screen works fine. newValue/oldValue properties are the property of the timer are they not? The script is pretty much running on the changes to the timer value. I have a lot of things getting calculated in this timer, and only one small section is looking for a value (tag) to change, and when it changes, I want to run a section of logic just once.

---

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [March 31, 2017, 8:52pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/4 "2017-03-31T20:52:58Z")

</div>

[quote][code]  
#variables  
data = event.source.parent.getComponent(‘Table’).data  
type = data.getValueAt(row,2)  
jID = data.getValueAt(row,3)  
doneBit = “[default]/StationTags/PowerT/Inverter/Station1/torque1Done”

torque1Status = system.tag.read(event.source.parent.getComponent(‘Station Name’).dataPath + “torque1Status”).value

#type = 4 for torque tool operations.  
if type == 4:  
if torque1Status == 0:  
jointData = system.db.runPrepQuery("SELECT \* FROM jointid WHERE jointID = (?) ", [jID])  
jData = system.dataset.toDataSet(jointData)  
toolName = jData.getValueAt(0,2)  
setpoint = jData.getValueAt(0,3)  
batchSize = jData.getValueAt(0,4)  
VIN = “this is temp vin”  
myID = system.util.getClientId()  
jointID = jID

```
	startPath = "TorqueToolStart"
	args = {"toolName":toolName, "pSet":setpoint, "batchSize":batchSize, "clientID":myID, "VIN_ID":VIN, "jointID":jointID, "doneBit":doneBit}
	id = system.sfc.startChart(startPath, args)
	
	system.tag.write(event.source.parent.getComponent('Station Name').dataPath + "torque1Status", 1)[/code]

```

[/quote]

So here is a stripped down version of what is going on. When “type” turns to a 4, I want to run the logic just once to start an instance of the SFC.

To attempt the oneshot I’m using the value of “torque1status”. If it is a zero I run the logic and at the end turn it to a 1. The SFC will turn it back to a zero at the end of the chart. The problem is the time it takes to both write and read to the tag. Is there a better way to handle this? Can I pause the logic on a write to insure that the write is complete before moving forward? (this is really part of another issue in the script, not here). The big issue here is that if it comes around to run again before the write has completed, then it will run a second instance of the SFC.

---

<div class="post-metadata">

**Author:** ![michael.palmer](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@michael.palmer](https://forum.inductiveautomation.com/u/michael.palmer)\
**Post date:** [April 3, 2017, 9:07pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/5 "2017-04-03T21:07:11Z")

</div>

no additional suggestions?

---

<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:** [April 4, 2017, 3:39am UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/6 "2017-04-04T03:39:58Z")

</div>

Have you tried using [system.tag.writeSynchronous](https://docs.inductiveautomation.com:8443/display/DOC79/system.tag.writeSynchronous)?

---

<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:** [April 4, 2017, 12:11pm UTC](https://forum.inductiveautomation.com/t/script-oneshot/13968/7 "2017-04-04T12:11:24Z")

</div>

[quote=“Kevin.Herron”]Have you tried using [system.tag.writeSynchronous](https://docs.inductiveautomation.com:8443/display/DOC79/system.tag.writeSynchronous)?[/quote]Can’t use that from the event dispatch thread. The UI will freeze.

Michael, your propertyChange event needs a construct something like this:`if event.propertyName=='type':
   if event.newValue == 4 and event.oldValue != 4:
      # Do something once when type becomes '4'
      .....`However, the key piece of information omitted from your initial post is that you aren’t looking at a simple property, but a dataset. And it’s a dataset on a different component. You need this script to be in the propertyChange event on the table, and look like this:`if event.propertyName=='data':
   newType = event.newValue.getValueAt(row,2)
   oldType = event.oldValue.getValueAt(row,2)
   if newType == 4 and oldType != 4:
      # Do something`Substitute an appropriate property reference on event.source for ‘row’.
