# Optimizing several tag writes

**URL:** <https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806>\
**Category:** Ignition\
**Created:** [November 13, 2018, 5:14pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806 "2018-11-13T17:14:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [November 13, 2018, 5:14pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806/1 "2018-11-13T17:14:49Z")

</div>

Hi,

I have a recipe screen that the operator can pick a part number for and enter in a work order. Once they do that they hit the load button and I take the info from a dataset and write it to the PLC. I wanted to ask you guys what the most efficient way to write the data to the tags is as we will be doing this process repeatedly. I have attached the working code I have now. I have looked into some of the different tag.write methods but was a little confused which one is best to use.

```auto
data = event.source.parent.HangerData

DryingRoom = data.getValueAt(0, "DryingRoom")
RobotNumber = data.getValueAt(0, "RobotNumber")
MaxDryTime = data.getValueAt(0, "MaxDryTime")
MinDryTime = data.getValueAt(0, "MinDryTime")
ManualPick = data.getValueAt(0, "ManualPick")

system.tag.write("SMS_HangerDataBuffer/CoatToProcess/DryTimeMax", MaxDryTime)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/DryTimeMin", MinDryTime)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/ManualStationRequired", ManualPick)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/RobotProgramNumber", RobotNumber)
system.tag.write("SMS_HangerDataBuffer/CoatToProcess/ShellCoatsDryRoom", DryingRoom)

system.nav.closeParentWindow(event)

```

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [November 13, 2018, 5:35pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806/2 "2018-11-13T17:35:44Z")

</div>

Use [system.tag.writeAll](https://docs.inductiveautomation.com/display/DOC79/system.tag.writeAll):

> Performs an asynchronous bulk write. Takes two sequences that must have the same number of entries. The first is the list of tag paths to write to, and then second is a list of values to write. This function is dramatically more efficient than calling write multiple times.

```auto
data = event.source.parent.HangerData

# List tags.
tags = ["SMS_HangerDataBuffer/CoatToProcess/DryTimeMax"]
tags.append("SMS_HangerDataBuffer/CoatToProcess/DryTimeMin")
tags.append("SMS_HangerDataBuffer/CoatToProcess/ManualStationRequired")
tags.append("SMS_HangerDataBuffer/CoatToProcess/RobotProgramNumber")
tags.append("SMS_HangerDataBuffer/CoatToProcess/ShellCoatsDryRoom")

# List values.
values = [data.getValueAt(0, "MaxDryTime")]
values.append(data.getValueAt(0, "MinDryTime"))
values.append(data.getValueAt(0, "ManualPick"))
values.append(data.getValueAt(0, "RobotNumber"))
values.append(data.getValueAt(0, "DryingRoom"))

# Write all values to tags.
system.tag.writeAll(tags, values)

```

---

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [November 13, 2018, 6:08pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806/3 "2018-11-13T18:08:21Z")

</div>

Thank you. is there a way to shorten the path part of the tag since they all have the same starting path?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [November 13, 2018, 6:14pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806/4 "2018-11-13T18:14:20Z")

</div>

```auto
tagRoot = "SMS_HangerDataBuffer/CoatToProcess/"
tags = [tagRoot + "DryTimeMax"]
tags.append(tagRoot + "DryTimeMin")
tags.append(tagRoot + "ManualStationRequired")
tags.append(tagRoot + "RobotProgramNumber")
tags.append(tagRoot + "ShellCoatsDryRoom") 

```

---

<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:** [November 13, 2018, 7:33pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806/5 "2018-11-13T19:33:47Z")

</div>

```auto
tagRoot = "SMS_HangerDataBuffer/CoatToProcess/"
tags = [tagRoot + x for x in ["DryTimeMax", "DryTimeMin", "ManualStationRequired", "RobotProgramNumber", "ShellCoatsDryRoom"]]

```

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [November 13, 2018, 8:15pm UTC](https://forum.inductiveautomation.com/t/optimizing-several-tag-writes/20806/6 "2018-11-13T20:15:09Z")

</div>

Although it doesn’t make much difference with a short list like this, you may find it advantageous to give the dataset columns names equal to the tag names . Then the list of tags _and_ list of values may both be constructed from one list of names in a for loop.
