# Perspective Barcode Data Handling Script for Multiple tags

**URL:** <https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 24, 2022, 6:51pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181 "2022-06-24T18:51:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_El-Hachem](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@George\_El-Hachem](https://forum.inductiveautomation.com/u/George_El-Hachem)\
**Post date:** [June 24, 2022, 6:51pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/1 "2022-06-24T18:51:00Z")

</div>

Hi, I’m trying to make an inventory tracking system and need multiple barcodes to scan them in and out of the closet. I already have the scan barcode button as well as 2 barcodes created. My problem is that no matter what barcode I scan, it writes the output to my first tag in my script. I need every barcode to write an output to a different tag. Can someone help me out?

 ![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/7/078cd98f7866a8f1224ffd110a3936989320a4dd.png)  
 ![Capture2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/b/8b69510eb5e67912dadad87e5f1b7ba48db8ed4e.png)  
 ![Capture3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/afb32e63fedb34332c6c44727dd2d1ca054ffda4.png)  
 ![Capture4](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/c/9cea384b1dbca1ba581c91c1f1fae9602c3937af.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:** [June 24, 2022, 6:55pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/2 "2022-06-24T18:55:35Z")

</div>

The ‘barcode scanned’ event is generic - _every_ barcode you scan will call in to the same event. You need to configure your ‘Scan Barcode’ action with additional “context”, which you then retrieve in the barcode event script and use to determine which tag to write to.

---

<div class="post-metadata">

**Author:** ![George\_El-Hachem](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@George\_El-Hachem](https://forum.inductiveautomation.com/u/George_El-Hachem)\
**Post date:** [June 24, 2022, 6:59pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/3 "2022-06-24T18:59:58Z")

</div>

![Capture5](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/dbab7d776a787cfcf49c50bf804b33fb3d138544.png)  
 ![Capture6](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/e/8ebe60a445cf59a77dcbe4a66cbbc0ff34c61562.png)

So I create context on my scan event then is this how I retrieve it in the barcode event script?

---

<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:** [June 24, 2022, 7:07pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/4 "2022-06-24T19:07:08Z")

</div>

Wait, I’m leading you down the wrong path.

Re-reading your first post, it seems like you know what the values are going to be in these barcodes?

---

<div class="post-metadata">

**Author:** ![George\_El-Hachem](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@George\_El-Hachem](https://forum.inductiveautomation.com/u/George_El-Hachem)\
**Post date:** [June 24, 2022, 7:08pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/5 "2022-06-24T19:08:14Z")

</div>

Yes I will be assigning the quantity of each item we have in inventory to each barcode corresponding to the item

---

<div class="post-metadata">

**Author:** ![George\_El-Hachem](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@George\_El-Hachem](https://forum.inductiveautomation.com/u/George_El-Hachem)\
**Post date:** [June 27, 2022, 12:31pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/6 "2022-06-27T12:31:56Z")

</div>

Hi PGriffith, I still need assistance with this, when you get the chance.

---

<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:** [June 27, 2022, 4:10pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/7 "2022-06-27T16:10:19Z")

</div>

What’s your desired flow, exactly?

Is it something like:

- You’re in your inventory room.
- You scan a barcode that’s physically in the room identifying a particular part.
- You enter a count in your Perspective interface
- The count is written to the appropriate tag

Or can you describe what you’re trying to do in more detail? The order of execution of events is important here, because it will dictate what you have access to when the barcode event fires.

---

<div class="post-metadata">

**Author:** ![George\_El-Hachem](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@George\_El-Hachem](https://forum.inductiveautomation.com/u/George_El-Hachem)\
**Post date:** [June 27, 2022, 6:11pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/8 "2022-06-27T18:11:47Z")

</div>

This is the exact flow of events I’m looking for.

---

<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:** [June 27, 2022, 6:21pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/9 "2022-06-27T18:21:24Z")

</div>

Okay. I’m going to assume the data that the barcode contains is something to identify which part you’re looking at.  
So the first thing you’ll need, somewhere, is a mapping from _part numbers_ to _tag paths_. At least from your screenshots, you have a bunch of numbered `Quantity` tags and nothing else.  
So what you probably want to do is something like this:

- Invoke your scan barcode action as you are. Don’t worry about ‘context’ or anything like that.
- In the “Barcode Scanned” event hook, you’ll open a view that will hold the actual data entry. Pass this view a _parameter_ - the actual part number that was scanned.
- In the view, you’ll probably have at least three components:
  - a Label with the part number that’s coming in as a parameter
  - an input field for entering the part count
  - a submit button

- The submit button will have a script that uses the part number and the mapping from above (a DB table or project library script or something similar) to determine which tag to write to, reads the value _from the input_, and writes back to that tag.

---

<div class="post-metadata">

**Author:** ![George\_El-Hachem](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@George\_El-Hachem](https://forum.inductiveautomation.com/u/George_El-Hachem)\
**Post date:** [June 30, 2022, 1:02pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/10 "2022-06-30T13:02:30Z")

</div>

Hello PGriffith! thank you so much for your help! I have just one more question. I’m new to ignition and was wondering how do I differentiate between barcode scripts for various views? I’m currently trying to make a barcode login page where a barcode is scanned to identify the user and all items checked in and out are linked to whoever is logged in?

---

<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:** [June 30, 2022, 2:21pm UTC](https://forum.inductiveautomation.com/t/perspective-barcode-data-handling-script-for-multiple-tags/61181/11 "2022-06-30T14:21:57Z")

</div>

If you have different sources of the barcode action, _that_ is where you could use the “context” field to differentiate. So you’d have a “login” context, and a “cycle count” context (or whatever other names you prefer). Then in the single barcode event handling script, you just immediately branch your logic, something like:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/696198f11b45053c4e9d29e5364cc675ee74d498.png)

```python
if context["context"] == "login":
    # do your login related barcode handling
elif context["context"] == "cycleCount":
    # do your cycle count barcode handling

```
