# Script - update property

**URL:** <https://forum.inductiveautomation.com/t/script-update-property/27993>\
**Category:** Ignition\
**Created:** [September 4, 2019, 7:05am UTC](https://forum.inductiveautomation.com/t/script-update-property/27993 "2019-09-04T07:05:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawel.kondol](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@pawel.kondol](https://forum.inductiveautomation.com/u/pawel.kondol)\
**Post date:** [September 4, 2019, 7:05am UTC](https://forum.inductiveautomation.com/t/script-update-property/27993/1 "2019-09-04T07:05:04Z")

</div>

Hi,

I have the following script on key released:

```auto
from time import sleep
if event.keyCode == event.VK_ENTER:
	if event.source.text == event.source.parent.getComponent('Label 9').text:

	#advance to next filed	
		event.source.parent.getComponent('Input1').requestFocusInWindow()
	else:
		event.source.text = "Incorrect Unit Serial Number"
		sleep(3)
		event.source.text = ""

```

Not sure why is not working properly.

```auto
event.source.text = "Incorrect Unit Serial Number"

```

is never displayed. Script just go to:

```auto
event.source.text = "".

```

Regards  
Pawel

---

<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:** [September 4, 2019, 12:10pm UTC](https://forum.inductiveautomation.com/t/script-update-property/27993/2 "2019-09-04T12:10:32Z")

</div>

You can’t (safely) use any form of sleep in event routines. You aren’t seeing the text display because your UI is freezing during the sleep, never giving your component (or any other) a chance to redraw themselves with the changes. You must use timer events or a timer component or an invokeLater() call to defer an action.

---

<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:** [September 4, 2019, 12:24pm UTC](https://forum.inductiveautomation.com/t/script-update-property/27993/3 "2019-09-04T12:24:43Z")

</div>

Here is a link for [system.util.invokeLater()](https://docs.inductiveautomation.com/display/DOC79/system.util.invokeLater) function in case you are unfamiliar with how it works.

---

<div class="post-metadata">

**Author:** ![pawel.kondol](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@pawel.kondol](https://forum.inductiveautomation.com/u/pawel.kondol)\
**Post date:** [September 5, 2019, 6:53am UTC](https://forum.inductiveautomation.com/t/script-update-property/27993/4 "2019-09-05T06:53:22Z")

</div>

Thanks for quick replay.

I tried this script:

````auto
from time import sleep
if event.keyCode == event.VK_ENTER:
	if event.source.text == event.source.parent.getComponent('Label 9').text:

	#advance to next filed	
		event.source.parent.getComponent('Input1').requestFocusInWindow()
	else:
   		def clickButton(button = event.source.parent.getComponent('Refresh')):
	   		import system
	   		button.doClick()
	   		system.gui.messageBox("Button has been clicked!")
  
	# Tell the system to invoke the function after
	# the current event has been processed
		system.util.invokeLater(clickButton)```

and I am getting this error.
Error running function from fpmi.system.invokeLater.

But it will be even better when I can call messageBox' for 3 seconds and then automatically closed and get back focus in window to correct the scan entry.

So the process look like:
Scan first entry verify against another value if not match then notify operators somehow.
Option 1. by displaying message in input text field for few seconds then automatically clear entry.
Option 2. Pop up message box with information. Unfortunately operators has only scanner to scan entries and no mouse or keyboard, so in option 2 message box will need to disappeared after few seconds automatically.

Regards
Pawel
````

---

<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:** [September 5, 2019, 1:01pm UTC](https://forum.inductiveautomation.com/t/script-update-property/27993/5 "2019-09-05T13:01:57Z")

</div>

Maybe try something like this

```auto
if event.keyCode == event.VK_ENTER:
    scan = str(event.newValue)
    stringCheck = event.source.parent.getComponent('Label 9').text
    if scan == stringCheck:
         your logic here
    else:
         def reset():
               event.source.text = ''
         event.source.text = 'Scan Rejected!'
         system.util.invokeLater(reset,3000)
```
