# Ignition Perspective Tag Value Change script help

**URL:** <https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [April 16, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922 "2024-04-16T17:53:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [April 16, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/1 "2024-04-16T17:53:42Z")

</div>

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:

```auto
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:

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [April 16, 2024, 6:46pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/2 "2024-04-16T18:46:38Z")

</div>

I have found that it is the

```auto
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?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 16, 2024, 6:58pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/3 "2024-04-16T18:58:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [April 16, 2024, 7:12pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/5 "2024-04-16T19:12:54Z")

</div>

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/9/994ec504d0e60dc1a47eec08f0e98f1319246e39.png)

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 16, 2024, 7:14pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/6 "2024-04-16T19:14:33Z")

</div>

Is it the escaped `\\s` after BN?

> **[regex101: build, test, and debug regex](https://regex101.com/r/Z61asj/1)**
>
> Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [April 16, 2024, 7:21pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/7 "2024-04-16T19:21:57Z")

</div>

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

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

```

line of code.

I was using this code

```auto
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.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 16, 2024, 7:23pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/8 "2024-04-16T19:23:47Z")

</div>

> [@Ryan\_Craig](#):
>
> except it has a 'u' infront of it for some reason...

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

---

<div class="post-metadata">

**Author:** ![Ryan\_Craig](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@Ryan\_Craig](https://forum.inductiveautomation.com/u/Ryan_Craig)\
**Post date:** [April 16, 2024, 7:43pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/9 "2024-04-16T19:43:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 16, 2024, 8:01pm UTC](https://forum.inductiveautomation.com/t/ignition-perspective-tag-value-change-script-help/88922/10 "2024-04-16T20:01:56Z")

</div>

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.
