# Session Events - "Context" Argument

**URL:** <https://forum.inductiveautomation.com/t/session-events-context-argument/57176>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [March 14, 2022, 6:58pm UTC](https://forum.inductiveautomation.com/t/session-events-context-argument/57176 "2022-03-14T18:58:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Kelly](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joe_kelly/32/30990_2.png) [@Joe\_Kelly](https://forum.inductiveautomation.com/u/Joe_Kelly)\
**Post date:** [March 14, 2022, 6:58pm UTC](https://forum.inductiveautomation.com/t/session-events-context-argument/57176/1 "2022-03-14T18:58:24Z")

</div>

I’m working on a project that involves scanning barcodes and noticed one of the arguments is documented as:  
`context: The user-defined context object associated with the barcode scan event.`

Can anyone give me an example of what this can be used for? I’m trying to see if I can use it to reference the component that fired the event on a per-session basis (i.e. multiple phones scanning barcodes using the same Perspective View page)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 14, 2022, 7:10pm UTC](https://forum.inductiveautomation.com/t/session-events-context-argument/57176/2 "2022-03-14T19:10:13Z")

</div>

The `context` of the Scan Barcode Event can be used to send static values which might be relevant to your handling of the Barcode Scanned Event logic.

Note that there is only ONE place for handling logic for scanning barcodes, but you might need to do different things based on what type of barcode is scanned, or perhaps based on the page which the event was triggered from. You’re not able to bind these contextual values, but you can supply static (unchanging) values.

Suppose you have two pages in different parts of your application. One of those pages scans QR codes, and one scans more traditional “UPC A” barcodes. If you scan a QR code you want to update one table in an associated DB, and if you scan UPC A you need to update a different table. You could provide a value within the context of the Scan Barcode Event which denotes the barcode type expected to be in use for this scan event, something like `type: "QR"`.

Then, in you Barcode Scanned Event (Session) you can modify your logic based off of that value:

```auto
if context.type:
    if context.type == "QR":
        # perform QR code logic
    elif context.type == "UPC A":
        # UPC A logic
    else:
        # default logic

```

---

<div class="post-metadata">

**Author:** ![Joe\_Kelly](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joe_kelly/32/30990_2.png) [@Joe\_Kelly](https://forum.inductiveautomation.com/u/Joe_Kelly)\
**Post date:** [March 14, 2022, 7:23pm UTC](https://forum.inductiveautomation.com/t/session-events-context-argument/57176/3 "2022-03-14T19:23:40Z")

</div>

Is that different from `data.barcodeType`? I guess I’m trying to figure out how I can use barcode scanning to fill out a text field, but that text field can’t be bound to something like a memory tag that the barcode event writes to because I will have multiple sessions using this page. Am I going down the wrong track with investigating the `context` argument?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 14, 2022, 7:55pm UTC](https://forum.inductiveautomation.com/t/session-events-context-argument/57176/4 "2022-03-14T19:55:47Z")

</div>

I was just providing a (bad) example to provide insight into how to use it – `data.barcodeType` is indeed another way of doing the same thing.

To set the value of some text field, you should use [system.perspective.sendMessage()](https://docs.inductiveautomation.com/display/DOC81/system.perspective.sendMessage) in conjunction with a listener on the text field. You might need to specify the sessionId argument as part of the sendMessage usage – I’m not sure if the event has implicit access to the session thread. If attempting to set the text of the text field is all you’re trying to do than you don’t need to use the context piece at all.

---

<div class="post-metadata">

**Author:** ![Joe\_Kelly](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joe_kelly/32/30990_2.png) [@Joe\_Kelly](https://forum.inductiveautomation.com/u/Joe_Kelly)\
**Post date:** [March 14, 2022, 8:43pm UTC](https://forum.inductiveautomation.com/t/session-events-context-argument/57176/5 "2022-03-14T20:43:28Z")

</div>

Perfect! I haven’t dug into messages at all yet, but I got it working pretty quickly with a bit of trial-and-error. Thanks!
