# Barcode Scanner Input Component Scripting

**URL:** <https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032>\
**Category:** Ignition\
**Tags:** ignition81, perspective, scripting\
**Created:** [December 12, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032 "2023-12-12T14:42:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/1 "2023-12-12T14:42:12Z")

</div>

Hello,  
I have the barcode scanner input component configured but would like to take the value of the first element array write it to a memory tag and delete the element so that each scan will always be the first element in the array. I've tried scripting this out on key press and on actionPerformed but it doesn't seem to work. Any suggestions?

Thanks!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/2 "2023-12-12T14:45:31Z")

</div>

Can you share the scripts you've tried?  
You probably want a property change event on the root of the scans array, for what it's worth.

---

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 2:54pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/3 "2023-12-12T14:54:01Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/e/6e1482721df4814fefa23fce25fee9d93260336b.png)

---

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 2:55pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/4 "2023-12-12T14:55:20Z")

</div>

I can't tell if I'm on the wrong event of that the pop functions doesn't work with this version of python or I'm using it incorrectly.

---

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 2:56pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/5 "2023-12-12T14:56:31Z")

</div>

Also tried it with self.props.clear() but didn't have any luck.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2023, 3:04pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/6 "2023-12-12T15:04:17Z")

</div>

Mutating the prop element in place isn't a good idea, because that mutation never makes it back to the actual property tree structure in the component. Instead explicitly set the data property to a new empty list.

---

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 3:52pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/7 "2023-12-12T15:52:02Z")

</div>

I changed it to this following:  
def valueChanged(self, previousValue, currentValue, origin, missedEvents):  
value = self.props.data[0]  
system.tag.writeBlocking('[C1Y]RackLabel/ScannedValue', str(value))  
emptyList =  
self.props.data = emptyList

But i'm getting the following error:  
com.inductiveautomation.ignition.common.script.JythonExecException  
Traceback (most recent call last):  
File "function:valueChanged", line 2, in valueChanged  
IndexError: index out of range: 0  
Sorry this is my first ignition project.

---

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 3:56pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/8 "2023-12-12T15:56:24Z")

</div>

Oh I got it, I took out  
value = self.props.data[0]  
system.tag.writeBlocking('[C1Y]RackLabel/ScannedValue', str(value))  
and put it inside of the actionPerformed event.  
Thanks for your help, property change events are awesome!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 12, 2023, 4:04pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/9 "2023-12-12T16:04:25Z")

</div>

> [@Nick\_V](#):
>
> But i'm getting the following error:

You were probably causing two changes to happen in rapid succession.  
In the first change, the scanned barcode adds a value to the data array.  
That triggers your property change event.

Then your property change event fires, and resets the data array to an empty array.  
That triggers your property change event 🙂  
Then that property change throws an error, because there's no index 0 on an empty list/array - which is the only thing saving you from an infinite loop (a risk in property change scripts, if they write back to themselves).

`actionPerformed` is a perfectly fine solution, but you could probably make the property change work as well; you would just have to filter off the `origin` parameter that's provided in your property change script; a scan will have a different value for `origin` than your script clearing it out will.

---

<div class="post-metadata">

**Author:** ![Nick\_V](https://avatars.discourse-cdn.com/v4/letter/n/b4bc9f/32.png) [@Nick\_V](https://forum.inductiveautomation.com/u/Nick_V)\
**Post date:** [December 12, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/barcode-scanner-input-component-scripting/83032/10 "2023-12-12T16:57:35Z")

</div>

Makes sense, thanks for explaining!
