Session Events - "Context" Argument

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)

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:

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

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?

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() 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.

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!