Barcode Data Handling Script Write to Indirect Tag

I watched this video, but I need a script to write to tags indirectly
I need the barcode data to write to the tag based on the machine number. I know how to write that in an expression but am not sure how to write it in the script. The machine number is currently on {view.params.MachineNumber} property.
The tag is Machine 01/Batch Number. I tried replacing the 01 with {view.params.MachineNumber} but no luck.

`system.tag.writeAsync([’[default]Machine {view.params.MachineNumber}/Batch Number’], [data.text])

I also tried

system.tag.writeAsync([’[default]Machine {MachineNumber}/Batch Number’], [data.text])
MachineNumber = {view.params.KettleNumber}

I’m using flex repeater instances of a machine template.

Youre supplying the literal tagpath ’[default]Machine {view.params.MachineNumber}/Batch Number’ to the tag write function. You need to evaluate the machine number part first and then add it to the string:

'[default]Machine %s/Batch Number' % (view.params.MachineNumber)

Ps. You may need some other parts to that view.params reference. Use the property selector to get the right reference to it

Thank you for the reply.

I tried

` system.tag.writeAsync([’[default]Machine %s /Batch Number’ % (view.params.MachineNumber)], [data.text])

and I confirmed that there is no other part to the view/params reference. It did not work.

The view params is from the Machine template that is being repeated in the flex repeater. When I scan a barcode from the flex repeater it does not go to anywhere. If I put a single machine tag it works, so I know it can work, but I need it to be dynamic to see the machine number and apply it to the machine’s tag based on the view that the Scan Barcode button is being opened on.

Sorry, my phone used the wrong apostrophes… or rather, I chose the wrong apostrophe on my phone.
You need to use ' instead of . I fixed it in my post.

I apologize, I did have the right apostrophe, this just does not like to show it that way. It did not work

I just checked in my Designer and I’m pretty sure you need to use:

Also, for all your code on the forum, you should wrap it inside preformatted text characters. Either ``` for multiple lines or ` for single lines.

Thank you. I tried adding self. and it still will not write the barcode to any tags.

This is the error

Error running session.onBarcodeDataReceived(session, data, context): Traceback (most recent call last): File “function:onBarcodeDataReceived”, line 3, in onBarcodeDataReceived at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser._parse( at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser$ParseFunction.load( at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser$ParseFunction.load( at$LoadingValueReference.loadFuture( at$Segment.loadSync( at$Segment.lockedGetOrLoad( at$Segment.get( at at at$LocalLoadingCache.get( at com.inductiveautomation.ignition.common.tags.paths.parser.TagPathParser.parse( at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.parseTagPath( at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.parseTagPaths( at com.inductiveautomation.ignition.common.script.builtin.AbstractTagUtilities.writeAsync( at jdk.internal.reflect.GeneratedMethodAccessor449.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) com.inductiveautomation.ignition.common.tags.paths.parser.TagPathFormatException: com.inductiveautomation.ignition.common.tags.paths.parser.TagPathFormatException: Token PROPERTY_SEPARATOR found after property name.

Should there be a space after %s?
If that fails, before you write to the tag, write the tag path string you’re creating to a component property or print it (when you use print in Perspective it will go into the wrapper.log, so make sure you have something in there unique to search for).

print '[default]Machine %s/Batch Number' % (self.view.params.MachineNumber)

Also, preformatted characters should be `, not an apostrophe. It’s the same key that tilde ~ is attached to (on QWERTY layout keyboards)


thank you. No, there is no space in the tag path after the machine number

This is the error I get:
Error running session.onBarcodeDataReceived(session, data, context): Traceback (most recent call last): File "<function:onBarcodeDataReceived>", line 2, in onBarcodeDataReceived NameError: global name 'self' is not defined

Sorry, I misunderstood where you were calling this from.
You can’t read the view’s properties from a session script. What I would do is to create a session property and bi-directionally bind the MachineNumber that you select to that. Then in the onBarcodeDataReceived script, you’ll be able to reference it using e.g. session.custom.MachineNumber

Aha, thanks. I created the session property MachineNumber but I’m not sure where to bind it. When you say the MachineNumber that you select do you mean the Scan Barcode button?

I have the Scan Barcode button on the Machine template as well as the text field that has a bi-directional indirect binding using the view params MachineNumber to the tag I’m trying to write to.

Yes, you would write to it when you click on the scan barcode button. Instead of using your view param on the label text binding, you would use the session property and remove the view param altogether.

Hello, I’m having a similar problem here where I’m trying to build an inventory system using barcodes. I have a scan barcode button, and have “Quantity” tags linked to a value in a table. I wrote the script in the video but it seems like all barcodes change one output in my table. How do I write a dynamic script so that each barcode corresponds to specific tags in my system?