Ignition Perspective Tag Value Change script help

I am trying to use a script that will pick out parts of a string entered and send those parts to another tag. I was able to get this script working on our Dev server:

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value != '':
		data = str(currentValue)
		import re
		m = re.search('.*PN: (.+)BN:\\s*([0-9]{7}).*', data)
		###system.tag.writeBlocking("[.]JobScan",m.group(0))
		system.tag.writeBlocking("[.]PartNumber",m.group(1))
		system.tag.writeBlocking("[.]BatchNumber",m.group(2))
	else:
		system.tag.writeBlocking("[.]PartNumber",'')
		system.tag.writeBlocking("[.]BatchNumber",'')

but then I transferred it to our production server and it doesn't seem to work now. I tried to switch the tag paths to point to the new tag paths and it still doesn't work:

def valueChanged(tag, tagPath, previousValue, currentValue, 
	if currentValue.value != '':
		data = str(currentValue.value)
		import re
		m = re.search('.*PN: (.+)BN:\\s*([0-9]{7}).*', data)
		###system.tag.writeBlocking("[.]JobScan",m.group(0))
		system.tag.writeBlocking(["[default]E398/E398/JobScanInfo/PartNumber.value"],[m.group(1)])
		system.tag.writeBlocking(["[default]E398/E398/JobScanInfo/BatchNumber.value"],[m.group(2)])
	else:
		system.tag.writeBlocking(["[default]E398/E398/JobScanInfo/PartNumber.value"],[''])
	    system.tag.writeBlocking(["[default]E398/E398/JobScanInfo/BatchNumber.value"],[''])

Am I missing something?
EDIT:
I tried to copy a working value change script from another tag to this one, and it doesn't work. It works perfectly fine for the tag I copied it from, but when I past it into this tags value changed script, it won't write to the other tag. Here is the script that works for one tag but not the other:

	if currentValue.value != '':	
		system.tag.writeBlocking('[default]{ENumber}/{ENumber}/JobScanInfo/PartNumberMem.value', currentValue.value)

I have found that it is the

m = re.search('.*PN: (.+)BN:\\s*([0-9]{7}).*', data)

part of the script. Any idea why it would work for our dev gateway and not our production gateway?

Your strings aren't what they're supposed to be, so the regex is failing?

Try
print repr(system.tag.readBlocking(["whateverTagThisIs"])[0].value)
In the script console on the production system.

I did this and it is printing out the correct value of the tag, except it has a 'u' infront of it for some reason...

image

But this is the same output as the project on our Dev server that is working correctly

Is it the escaped \\s after BN?

I don't think so. I messed around with that on my project that is working and it is giving me the correct output every time. When I try it on my other gateway, it won't write anything as soon as I put the

m = re.search('.*PN: (.+)BN:\\s*([0-9]{7}).*', data)

line of code.

I was using this code

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value != '':
		import re
		m = re.search('.*PN: (.+)BN:\s*([0-9]{7}).*', data)
		system.tag.writeBlocking('[default]{ENumber}/{ENumber}/JobScanInfo/PartNumberMem.value', currentValue.value)

starting with just the writeBlocking, then started adding more line by line until it wouldn't print anymore.

Even if I comment out the line, it still stops it from writing until I completely delete it.

That just means it's a Unicode string (supporting a wider character set). You shouldn't have to worry about it.

1 Like

I have found out that the issue is the {} around the 7, but I am not sure of a work around

Oh, wait, are you writing this script out in a UDT?

I think you're getting hit by a bug with parameter referencing; it's attempting to replace the curly brace portion as if it were a UDT parameter.

Try putting your code in the project library (in your gateway scripting project) and calling it from your tag.