# Latching tag's string value to a Memory Tag

**URL:** <https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [October 9, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205 "2023-10-09T14:51:41Z")\
**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:** [October 9, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/1 "2023-10-09T14:51:41Z")

</div>

I am having a problem where, my machine is sending a string value to a tag, but the value only stays momentarily. I am trying to create a memory tag, that would latch this string, so that I can use it even after the original tags value goes away.

Currently I have a tag event script, On Value Change, on the original tag that looks like this:

```auto
if "[.]CurrentJob.value" != "":
	system.tag.writeToTag(['[default]E374/JobNumberTest_Mem'], [currentValue.value])

```

Where the "CurrentJob" tag is flashing the string value, and the "JobNumberTest\_Mem" tag is the one I am trying to latch it to.

This script seems to write to the memory tag fine, but once the string value goes away, it also goes away on the memory tag. Does anyone know of a script I can write to latch the string value on the "JobNumberTest\_Mem" tag?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 9, 2023, 3:00pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/2 "2023-10-09T15:00:49Z")

</div>

> [@Ryan\_Craig](#):
>
> it also goes away on the memory tag

There must be some other script doing that part. Memory tags don't change by themselves.

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [October 9, 2023, 3:03pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/3 "2023-10-09T15:03:15Z")

</div>

Hello,

This works for me.

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if len(currentValue.value) > 0:
		system.tag.writeBlocking(["[US08Batch]00/String2"],[currentValue.value])

```

Regards,

Frank

---

<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:** [October 9, 2023, 3:07pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/4 "2023-10-09T15:07:36Z")

</div>

I just created the memory tag and the only thing I have pointing to that tag is that script. I am not sure what else would be affecting the memory tag.

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [October 9, 2023, 3:08pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/5 "2023-10-09T15:08:32Z")

</div>

I think your if condition is allowing a None value to pass.

---

<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:** [October 9, 2023, 3:08pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/6 "2023-10-09T15:08:50Z")

</div>

This works the same as my script did..

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/0/20b993f371f504ce555aca2654989f84946bf72c.png)

It will send the value to the other string, but once the value disappears on the CurrentJob tag, it disappears on the memory tag as well..

---

<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:** [October 9, 2023, 3:09pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/7 "2023-10-09T15:09:44Z")

</div>

How would I change that?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 9, 2023, 3:13pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/8 "2023-10-09T15:13:36Z")

</div>

> [@Ryan\_Craig](#):
>
> `if "[.]CurrentJob.value" != "":`

Actually, you've quoted a tagpath and are expecting it to be a value. It's still a string, and always different from the empty string

If this event is on the `CurrentJob` tag, then all you need is this:

```auto
if currentValue.value:

```

First, a tag event gives you the new value in a qualified value variable, then both empty strings and `None` evaluate to `False` in a conditional context.

---

<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:** [October 9, 2023, 3:16pm UTC](https://forum.inductiveautomation.com/t/latching-tags-string-value-to-a-memory-tag/80205/9 "2023-10-09T15:16:44Z")

</div>

This seemed to work!

Thank you!
