# Perspective Memory String Array Write

**URL:** <https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 8, 2023, 5:44pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780 "2023-06-08T17:44:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 5:44pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/1 "2023-06-08T17:44:12Z")

</div>

I am getting to know the tags more and have been having trouble getting information to write to a memory string array. I have a multiple selection drop down that I am taking the values and trying to write to a tag. The problem is it will not write or if I use a loop write over the old value and not append (I can't find where if there is a system perspective function to do this)

Without a loop I have this:

```auto
def runAction(self, event):
	supervisors = self.getSibling("superDropDown").getChild("supervisorSelect").props.value
	system.tag.writeBlocking('[default]Alarm/supervisors', [self.session.custom.JW.alert.supervisors])
	

```

And then when I add a loop and it actually writes but write over this is what I have so far:

```auto
def runAction(self, event):
	supervisors = self.getSibling("superDropDown").getChild("supervisorSelect").props.value

	for i in supervisors:
		system.tag.writeBlocking("[default]Alarm/supervisors", i )

```

---

<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:** [June 8, 2023, 5:47pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/2 "2023-06-08T17:47:30Z")

</div>

Tags are meant to be written as a whole. Read the tag to get the current array. Construct a new array modified as desired, then write that back to the tag.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 5:53pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/4 "2023-06-08T17:53:13Z")

</div>

the length of the array changes so I don't know if that is the problem? But I get this error  
ValueError: Length of values does not match length of paths.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 5:57pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/5 "2023-06-08T17:57:04Z")

</div>

So I tried that before and it didn't work. This was my thought process of how I would go about that:

```auto
def runAction(self, event):
	addition = self.getSibling("superDropDown").getChild("supervisorSelect").props.value
	
	
	supervisors = system.tag.readBlocking ("[default]Alarm/supervisors")
	values = supervisors.append (addition)
	system.tag.writeBlocking('[default]Alarm/supervisors', values)

```

If you could tell me where I am going wrong that would be great!

---

<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:** [June 8, 2023, 6:00pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/6 "2023-06-08T18:00:55Z")

</div>

> [@Grace\_Tarler](#):
>
> Length of values does not match length of paths.

You need to supply lists to `writeBlocking`. If writing a single tag, and its value is a list, it still must be encapsulated in another list.

{ `readBlocking` has a backward compatibility quirk that lets it handle a single tag path. But still returns a list (of one) of qualified values.}

Your script is not supplying lists to the functions, and not properly extracting your actual tag value from the read list of qualified values. Please review the documentation for these functions again.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 6:05pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/7 "2023-06-08T18:05:19Z")

</div>

I am so sorry but still very confused. I tried looking through the manual but did not find anything. Would you be able to provide an example of the syntax you are trying to outline.

Are you saying it should be something as follows:

```auto

# Create a list with the tag paths to be updated.
paths = ["[default]Folder/Tag_A","[default]Folder/Tag_A"]
 
# Create a list with the update values, one value for each path.
values = [1,2]
 
# Execute the write operation.
system.tag.writeBlocking(paths, values)

```

which would have Tag\_A have both 1 and 2?

---

<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:** [June 8, 2023, 6:08pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/8 "2023-06-08T18:08:01Z")

</div>

There are examples and explanations of the parameters and return values for each of these functions:

[system.tag.readBlocking()](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking)

[system.tag.writeBlocking()](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking)

---

<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:** [June 8, 2023, 6:08pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/9 "2023-06-08T18:08:47Z")

</div>

> [@Grace\_Tarler](#):
>
> which would have Tag\_A have both 1 and 2?

No, Tag\_A would get just that last value.

---

<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:** [June 8, 2023, 6:09pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/10 "2023-06-08T18:09:22Z")

</div>

Wrong:  
`system.tag.writeBlocking('[default]Alarm/supervisors', values)`  
Right  
`system.tag.writeBlocking(['[default]Alarm/supervisors'], [values])`

---

<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:** [June 8, 2023, 6:10pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/11 "2023-06-08T18:10:45Z")

</div>

> [@Transistor](#):
>
> ~~Right~~  
> `system.tag.writeBlocking(['[default]Alarm/supervisors'], values)`

`system.tag.writeBlocking(['[default]Alarm/supervisors'], [values])`

{ The OP is trying to write to an array tag. }

---

<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:** [June 8, 2023, 6:13pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/12 "2023-06-08T18:13:20Z")

</div>

Fixed, thanks, Phil. I assumed that values was already an array mucha like "args" in the documentation examples. It would have tripped me up too.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 6:15pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/13 "2023-06-08T18:15:13Z")

</div>

Unfortunately that still did not work.

```auto
def runAction(self, event):
	supervisors = self.getSibling("superDropDown").getChild("supervisorSelect").props.value
	
	system.tag.writeBlocking(['[default]Alarm/supervisors'], [supervisors])
	system.perspective.print(supervisors)

```

I printed the supervisors to make sure it was pulling the data and it was able to print this array in the console:  
14:13:06.604 [Browser Thread: 61073] INFO Perspective.Designer.Workspace - : [u' 5542', u' 925']

---

<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:** [June 8, 2023, 6:18pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/14 "2023-06-08T18:18:03Z")

</div>

Hmm. If that tag is a string array, I would have expected that to work.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 6:19pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/15 "2023-06-08T18:19:52Z")

</div>

Hmmm.... Well that makes me feel a little better that I am not going crazy and making a obvious mistake on why this isn't working

Thank you!

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 8, 2023, 8:06pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/16 "2023-06-08T20:06:44Z")

</div>

I think I figured it out that since it is from a database it is adding a u before the string not allowing the write for the tag

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 8, 2023, 8:11pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/17 "2023-06-08T20:11:45Z")

</div>

> [@Grace\_Tarler](#):
>
> adding a u before the string not allowing the write for the tag

The u in [u' 5542'] just means that the string is unicode encoded. It is not actually part of the string.

Throw this into a script console to see what I mean.

```auto
test = [u' 5542']
print test[0]

```

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [June 9, 2023, 12:35pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/18 "2023-06-09T12:35:18Z")

</div>

```auto
def runAction(self, event):
	supervisors = self.getSibling("superDropDown").getChild("supervisorSelect").props.value
	data_email =system.db.runNamedQuery("Select_JER_Supervisor_Email")
	supers_email = system.dataset.toPyDataSet (data_email)
	select_email = []
	for num in supers_email:
		for select_num in supervisors:
			if num[0] == select_num:
				select_email.append(str(num[1]))
	system.tag.writeBlocking(["[default]Alarm/supervisor_email"], [select_email])

```

this is what I came up with that worked and just ended up needing to convert the index to string in order to read it without seeing the u for unicde and write to a variable and then write that variable array to the array tag

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 9, 2023, 12:44pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/19 "2023-06-09T12:44:20Z")

</div>

> [@Grace\_Tarler](#):
>
> ```auto
> select_email = []
> for num in supers_email:
> for select_num in supervisors:
> if num[0] == select_num:
> select_email.append(str(num[1]))
> 
> ```

This can be simplified a bit.

first, this:

```python
for select_num in supervisors:
	if num[0] == select_num:

```

is equivalent to

```python
if num[0] in supervisors:

```

then, we can put the whole loop in a list comprehension:

```python
select_email = [num[1] for num in supers_email if num[0] in supervisors]

```

I'd also suggest finding a more meaningful name than 'num' for your variable.

edit:  
May I ask what that whole thing is about ?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 9, 2023, 12:47pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/20 "2023-06-09T12:47:58Z")

</div>

> [@Grace\_Tarler](#):
>
> convert the index to string in order to read it without seeing the u for unicde

I don't know what this means or why it's important. Assuming that num[1] is a string, unicode or not, the str() is doing nothing but taking up execution time, however small that may be.

I would also suggest using the column names instead of their index, so that whomever comes after you will have a little easier time figuring out what's going on.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 9, 2023, 12:54pm UTC](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780/21 "2023-06-09T12:54:06Z")

</div>

I agree.  
You can use column names instead of index when accessing things in a `pyDataSet`.  
It makes the whole thing that much clearer.

They can also be unpacked, but that might be unpractical if there are more columns than you need to use. But let's say your `supers_mail` dataset has 2 columns `user_name` and `user_email`, you can do this:

```python
for name, email in supers_mail:
    print name, email

for row in supers_mail:
    print row['user_name'], row['user_email']

for row in supers_mail:
    print row[0], row[1]

```

Those are equivalent when using pyDataSets.  
With the little exception that the first one, unpacking, requires you to use as many variables as there are elements to unpack, so it won't work if your dataset has more than 2 columns.  
If it had a third column `user_phonenum`, you'd need to do this, even if you don't need the phone number:

```python
for name, email, num in supers_mail:
    print name, email

```

[Next page](https://forum.inductiveautomation.com/t/perspective-memory-string-array-write/74780.md?page=2)
