# invokeLater

**URL:** <https://forum.inductiveautomation.com/t/invokelater/8329>\
**Category:** Ignition\
**Created:** [April 17, 2014, 2:29pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329 "2014-04-17T14:29:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [April 17, 2014, 2:29pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/1 "2014-04-17T14:29:30Z")

</div>

Within a gateway event script I want to write a value to a tag after some other events have completed. Currently having some problems with the timing. I would like to try the system.util.invokeLater function, but receive an attribute error in the console stating the object has no attribute ‘invokeLater’. Any ideas?

```
[code] def reset():
		import system
		system.tag.write("Conveyor\Carrier",0)	
	system.util.invokeLater(reset)[/code]

```

Ignition 7.6.6

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [April 17, 2014, 2:33pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/2 "2014-04-17T14:33:52Z")

</div>

Python is sensitive to white space. Try fixing your indentations:

```auto
def reset():
         import system
         system.tag.write("Conveyor\Carrier",0)   
system.util.invokeLater(reset)
```

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [April 17, 2014, 2:39pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/3 "2014-04-17T14:39:33Z")

</div>

The whitespace was only a problem with the paste. I’ve corrected it, still no change.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 17, 2014, 3:06pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/4 "2014-04-17T15:06:44Z")

</div>

The system.util.invokeLater function doesn’t exist in the Gateway scope. It has nothing to do with Gateway events. You are not able to use the system.util.invokeLater function in a Gateway Event Script.

The system.util.invokeLater only works with GUI events. Since the Gateway scope has no GUI there is no place for this function in this scope.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [April 17, 2014, 3:07pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/5 "2014-04-17T15:07:34Z")

</div>

[ignore]Maybe paste some more of your code and the exact error message?[/ignore]

Thanks, Nick.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 17, 2014, 3:09pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/6 "2014-04-17T15:09:37Z")

</div>

You want to write a value to a tag after what events are completed?

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [April 17, 2014, 3:57pm UTC](https://forum.inductiveautomation.com/t/invokelater/8329/7 "2014-04-17T15:57:19Z")

</div>

This is running on a gateway tag change script. The problem I am having is after the order is completed and is deleted from the table the next tag change still writes the non-existent order to tags. It isn’t until after the second tag change following the order completion that it moves to the next order.

[code]import system

if newValue.value == 1:

```
#Get next order data
model = system.db.runScalarQuery("SELECT MODEL FROM tblSequence WHERE SortOrder = 1")
orderNumber = system.db.runScalarQuery("SELECT ORDER_NUMBER FROM tblSequence WHERE SortOrder = 1")
sn = system.db.runScalarQuery("SELECT SERIAL_NUMBER FROM tblSequence WHERE SortOrder = 1")
gs = system.db.runScalarQuery("SELECT SEQUENCE_NUMBER FROM tblSequence WHERE SortOrder = 1")
baseMachine = system.db.runScalarQuery("SELECT BASE_MACHINE FROM tblSequence WHERE SortOrder = 1")
description = system.db.runScalarQuery("SELECT MATERIAL_DESCRIPT FROM tblSequence WHERE SortOrder = 1")

#Count carriers within order
carrier = system.tag.read("Conveyor\Carrier").value
count = carrier + 1
totalCarrier = system.db.runScalarQuery("SELECT TOP 1 CARRIER FROM tblLoadUnloadData WHERE MODEL = '%s' ORDER BY CARRIER DESC" % model)

#Get load and unload stations for current carrier within order
load = system.db.runScalarQuery("SELECT LOAD_POINT FROM tblLoadUnloadData WHERE MODEL = '%s' AND CARRIER = %d" % (model, count))
unload1 = system.db.runScalarQuery("SELECT UNLOAD_POINT_1 FROM tblLoadUnloadData WHERE MODEL = '%s' AND CARRIER = %d" % (model, count))
unload2 = system.db.runScalarQuery("SELECT UNLOAD_POINT_2 FROM tblLoadUnloadData WHERE MODEL = '%s' AND CARRIER = %d" % (model, count))
loadDescription = system.db.runScalarQuery("SELECT DESCRIPTION FROM tblLoadUnloadData WHERE MODEL = '%s' AND CARRIER = %d" % (model, count))
		
#Write carrier data to PLC for carrier at Stop 43
system.tag.write("Conveyor\Model",model)
system.tag.write("Conveyor\Load_Point",load)
system.tag.write("Conveyor\Unload_Point_1",unload1)
system.tag.write("Conveyor\Unload_Point_2",unload2)
system.tag.write("Conveyor\Serial_Number",sn)
system.tag.write("Conveyor\Grand_Sequence",gs)
system.tag.write("Conveyor\Total_Carriers",totalCarrier)
system.tag.write("Conveyor\Order_Number",orderNumber)
system.tag.write("Conveyor\Base_Code",baseMachine)
system.tag.write("Conveyor\Description",description)
system.tag.write("Conveyor\Load_Description",loadDescription)

#When all carriers associated with an order are processed move to next order
if carrier >= totalCarrier:
	system.tag.write("Conveyor\Carrier",0)	
	system.db.runPrepUpdate("DELETE FROM tblSequence WHERE ORDER_NUMBER = ?", [orderNumber])
	system.db.runPrepUpdate("UPDATE tblSequence SET SortOrder = SortOrder - 1")
else:
	system.tag.write("Conveyor\Carrier",count)[/code]
```
