Use Scan Barcode action to return data to specific instance of embedded view

I'm having some trouble using the Scan Barcode action in a way that allows the data from the most recent scan to populate into the view that called the scan. My idea was to use the Context section of the Scan Barcode action to pass a parameter from the instance of the view calling for the scan into the context of the scan. Now the session event script that triggers after the barcode will have an identifier for the component that called the scan. This would allow me to send a message of the type "barcodeScanned" from the session event script, with a return identifier supplied in the payload of the message that each instance of the embedded view could check against their own identifier. The Barcode Data handling script for this implementation would look like this:

The problem is, there doesn't seem to be a way to supply anything other than a constant value for the context of a scan when configuring the Scan Barcode action.

I cannot reference the properties of the component doing the action, and I cannot call the Scan Barcode action using a script the way I can with other actions in the system.perspective path. This results in no way to differentiate between instances of the view that initiated the action, as far as I can tell.

Is there a way to pass the data from a Barcode scan session event to the specific instance of the view that triggered it?

1 Like

I have found a workaround, from this post by u/stevenson. In my implementation, the view that needs data scanned into it from the session event first sets a session.custom property to the value of the return ID I wanted as context for the barcode scanner event, then the barcode scanner reads this session.custom property to provide the correct returnID in the payload of the barcodeScanned message.

I think that the session custom variable is an inelegant solution, but the only one I can think of without a way to activate the session barcode scanner using a system method.

1 Like