# Scan Barcode how to show data in the label (onBarcodeDataReceived)

**URL:** <https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [May 24, 2022, 2:40pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958 "2022-05-24T14:40:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [May 24, 2022, 2:40pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/1 "2022-05-24T14:40:12Z")

</div>

Hello.

I’m trying to send information for a **Label** using the Scan Barcode (with def onBarcodeDataReceived(session, data, context) ).  
I can pass information using Tag (system.tag.writeAsync(‘Writable/scantest’, vCamSerial)) but I would like to pass directly to the **Label**.

Button trigger onClick → Scan Barcode

```auto
Session Event:
def onBarcodeDataReceived(session, data, context)
	SCRIPT.canCam([data.text])

```

* * *

```auto
Project Library:

def scanCam(vCamSerial):

#works but I don't want to use TAG
 system.tag.writeAsync('Writable/scantest', vCamSerial) 

#not works
 self.getSibling("Label_0").props.text = vCamSerial 

```

Thanks

---

<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:** [August 4, 2022, 6:56pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/2 "2022-08-04T18:56:55Z")

</div>

The event is in the session, so it doesn’t have direct access to pages and views. Send a message at session scope. Have a handler on the label listening for session scope.

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [August 4, 2022, 7:15pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/3 "2022-08-04T19:15:14Z")

</div>

Is there some way to read a barcode (mobile onBarcodeDataReceived) to send the value without using TAG.

---

<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:** [August 4, 2022, 7:22pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/4 "2022-08-04T19:22:53Z")

</div>

Yes, send a message to the label with `system.perspective.sendMessage`.

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [August 4, 2022, 7:31pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/5 "2022-08-04T19:31:48Z")

</div>

Thanks, I will take a look at this method, I didn’t use sendMessage yet.

---

<div class="post-metadata">

**Author:** ![OscarLucas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/oscarlucas/32/6417_2.png) [@OscarLucas](https://forum.inductiveautomation.com/u/OscarLucas)\
**Post date:** [August 31, 2022, 11:29am UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/6 "2022-08-31T11:29:27Z")

</div>

Do you have an example? I am trying to get out user can not read codes from other users. is this the best way to use it?

---

<div class="post-metadata">

**Author:** ![Thiago\_Vilela](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/thiago_vilela/32/37352_2.png) [@Thiago\_Vilela](https://forum.inductiveautomation.com/u/Thiago_Vilela)\
**Post date:** [October 27, 2022, 1:55pm UTC](https://forum.inductiveautomation.com/t/scan-barcode-how-to-show-data-in-the-label-onbarcodedatareceived/59958/7 "2022-10-27T13:55:14Z")

</div>

Sorry for the late reply. 🤦🏽‍♂️

This is how I did.

**Button (Event):**  
OnActionPerformed:

```auto
  def runAction(self, event):
 	Consult.ConsultMaterials.CleanConsult(self)

```

**Script (Project library)**

```auto
def scanCam(vCamSerial):
	system.perspective.sendMessage(
	'getBarcodeScanned'
	,payload = {
			 'vSession':123
			,'vLabelScanned':vCamSerial
				}
	,scope="session"
	)

```

**OnClick:**  
Scan Barcode

**Script Message Handler:** Label that will receive the scan info:

```auto
def onMessageReceived(self, payload):
	#getBarcodeScanned -> Message Type 
     #Session, Page -> Listen Scopes

	vSession = payload['vSession']
	vLabelScanned = payload['vLabelScanned']
	
	self.props.text = vLabelScanned
	self.getSibling("tfConsLabelScan").props.text = vLabelScanned
	Consult.ConsultMaterials.ConsultMaterial(self,vLabelScanned)

```
