Barcode scanner component ignores the initial change

Hello everyone,

For a project, I am using the barcode scanner component on perspective. When the user scans the barcode a popup window should be popped up; however when the user launches the session, the popup window pops up after the 2nd scan, the component completely ignores the action for the 1st scan or better to say the first data.
I wrote the code below for the property change script of the barcode scanner data:

	if currentValue.value != previousValue.value:
		system.perspective.openPopup('myPopupId', 'PopUp')

image

Any idea of how this component can be programmed to not ignore the initial change?
Thank you!

If previousValue.value is null (python None), the != operator doesn’t work the way you think (comparisons to None are always false). Try this:

if previousValue.value is None or previousValue.value != currentValue.value:
    system.perspective......
1 Like

Thank you very much for your response. Appreciate it! I tried the code you wrote; however, nothing has changed. Is it ok if I have the change script on the
data component? Not the array?
image

Consider putting logging before the if statement to see what is happening. Something like this:

system.util.getLogger('MyLogger').infof("valueChange(..., %s, %s,...)", previousValue, currentValue)

This will let you know if the event is firing at all for the first scan. If it’s not, you’ll need help from IA.

ON my logs,
I get these messages:

The error is:
Error running property change script on BarcodeScannerInput.props.data: Traceback (most recent call last): File “function:valueChanged”, line 3, in valueChanged AttributeError: ‘NoneType’ object has no attribute ‘value’

Is this normal?

No, not normal. My code suggestion was buggy. Also, if you look at the array for changes, you will have to use a subscript after .value.
Try this:

if previousValue is None or previousValue.value != currentValue.value:
    system.perspective......
1 Like

It works like a charm now! Thank you very much!