# Barcode data to component property

**URL:** <https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 11, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137 "2024-03-11T15:26:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 11, 2024, 3:26pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/1 "2024-03-11T15:26:26Z")

</div>

I am creating an app that requires barcode scans via mobile device camera on multiple different pages of the project. For my record look up page, I have a button that allows the user to scan the barcode. In an ideal world, I want the scanned barcode text to populate a text input field's text property called "MasterListSearchBar" on my view "OP10MasterList", but something seems to be wrong with my process. Any guidance?

Barcode Scanner Button Event:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/f/1f58babd9a613f90efbb3080a3af62cd1b4cb9cb.png)

Barcode Session Event:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/2/72d1c07629084cb370dd01b0366d69d026486b94.png)

---

<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:** [March 11, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/2 "2024-03-11T15:33:32Z")

</div>

`system.gui` functions are Vision only, not Perspective. You need to emit a message (`system.perspective.sendMessage`) to go from your `onBarcodeDataReceived` back to your active Perspective session context.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 11, 2024, 3:49pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/3 "2024-03-11T15:49:23Z")

</div>

I am a bit new to ignition so I am not too sure how I would go about doing that in application. Can you demonstrate?

---

<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:** [March 11, 2024, 4:00pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/4 "2024-03-11T16:00:20Z")

</div>

It's annoyingly indirect.

Basically:  
In your barcode handling event, send out a message using  
`system.perspective.sendMessage`. That message will have a scope and handler name associated with it. You 'broadcast' a message that says "a barcode scan related to `MasterListSearch` happened.

Then, in your _component_, you configure a message handler that listens for the 'type' of message you just broadcast, read the new value out of the "payload" of that message, and assign it to the text field.

See this video for more details:

> **[Message Handlers Video at Inductive University](https://www.inductiveuniversity.com/video/message-handlers/8.1)**
>
> Learn how to use Component Message Handlers to pass data between components and views.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 11, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/5 "2024-03-11T16:04:24Z")

</div>

You can also write the barcode string to a tag and bind your component's text value to the tag. Useful if you need to reference in more than one place, or if you want to setup a history of the barcodes scanned, or just view what the last scan was by inspecting the tag in designer/gateway.

---

<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 12, 2024, 1:05am UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/6 "2024-03-12T01:05:21Z")

</div>

> [@bkarabinchak.psi](#):
>
> barcode string to a tag

Don't do this if multiple clients will be working simultaneously....

Perhaps write to a session custom prop.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 13, 2024, 11:41am UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/7 "2024-03-13T11:41:52Z")

</div>

This is my new process. I am still getting nothing populated in the text input field.  
Barcode Scan Button:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/6/76d1578dce87f2bf0240c40207a8298d73242c35.png)  
Session Barcode Event:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/f/bf92d2a8dc2491034a5ce714a07d54f1c8ff0276.png)  
Text Input Field Message Handler:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/6/867e1f31e75e410304f495fbd845f45bea2593f1.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 13, 2024, 12:00pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/8 "2024-03-13T12:00:36Z")

</div>

Potentially two things -  
1 -

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

Look at the red underline and the red mark on the right hand side, circled. These indicate there is a syntax error that will prevent this code from compiling or running. The issue here is your line 3 should be indented. You always have to indent after a `if` statement.

2 (Potentially) -  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/2/328d76b549364d6e3b5df30ac269e2e51e86f170.png)

I think this should be session. Right now it's checked to Page so it's only listening for messages from 'MasterListSearch' from other components on the page, but you are sending it from a Session event, so I think this listen scope may need to change to session.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 13, 2024, 12:00pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/9 "2024-03-13T12:00:49Z")

</div>

The indentation was incorrect but even when fixed it still doesn't run ^^

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 13, 2024, 12:06pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/10 "2024-03-13T12:06:57Z")

</div>

Look at my second comment about listen scopes. Also check your gateway logs to see if some error is being thrown.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 13, 2024, 12:20pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/11 "2024-03-13T12:20:13Z")

</div>

I changed the session scope and I see no errors being thrown as well. Is there a syntax issue with how I am referencing the text property?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 13, 2024, 12:26pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/12 "2024-03-13T12:26:56Z")

</div>

Oh I should have caught this.

Take a look a how the payload is in the documentation [system.perspective.sendMessage | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-perspective/system-perspective-sendMessage) - it's a dictionary.  
So sending the payload should be like `{'barcode':data.text}` and on the recieving end `self.props.text = payload['barcode']`

I will say `data.text` seems odd though if data is a `list` as per the param documentation  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37bd8892490b3a6053c180cab249c9032f0fc652.png)  
Are you sure that is grabbing things appropriately? Never hurts to use a loggers if you want to keep track of what is happening.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 13, 2024, 12:50pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/13 "2024-03-13T12:50:14Z")

</div>

Changed the code to this below:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/3/e3f932bdcffa5c3256385f31f12bd4a134364689.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/3/23d707e5f364929eb5465381c557b412ce8adea5.png)  
I don't see anything being printed in the console when I scan anything, let alone the text field populating. Does that mean my condition is incorrect?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 13, 2024, 1:03pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/14 "2024-03-13T13:03:14Z")

</div>

Yes I would print out the `context` variable before any if statement see what that looks like see if your condition is correct.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 13, 2024, 1:09pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/15 "2024-03-13T13:09:13Z")

</div>

Got rid of all conditions to test it yet still nothing. Is the methodology in which I am sending the message incorrect? Maybe the message isn't being received by the component? This is my third day on ignition so this is all new to me haha.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 13, 2024, 1:11pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/16 "2024-03-13T13:11:12Z")

</div>

Try this in the `onBarcodeDataReceived` -

```auto
    logger = system.util.getLogger("Barcode Logger")
    logger.info("Barcode receieved!")

```

And then scan a barcode and check your logs

Also make sure you are saving your project after change.

Also I highly recommend going through [https://inductiveuniversity.com/](https://inductiveuniversity.com/)

---

<div class="post-metadata">

**Author:** ![Mustafa\_Shah](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mustafa\_Shah](https://forum.inductiveautomation.com/u/Mustafa_Shah)\
**Post date:** [March 14, 2024, 12:04pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/17 "2024-03-14T12:04:39Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/8/98b1ca86d68c1a2719d22d83cd8136d4cc355f85.png)  
This is my most recently updated code. Nothing shows up in my session log.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 18, 2024, 1:13pm UTC](https://forum.inductiveautomation.com/t/barcode-data-to-component-property/87137/18 "2024-03-18T13:13:16Z")

</div>

It would be in your gateway logs, not the browser console.
