# Perspective working with tags using script

**URL:** <https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 12, 2024, 6:00pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205 "2024-03-12T18:00:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [March 12, 2024, 6:00pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205/1 "2024-03-12T18:00:16Z")

</div>

Have a group of tags - tags1...tag24. I would like to find the highest value in that group of tags.  
I was using this script on an individual tag to see when the value changed for that tag but I dont think that is the best way. I would have to add this to all 24 tags.

```auto
current_y = currentValue
		current_max = system.tag.readBlocking("[.]Y_Max") [0].value
		if current_y >= current_max:
			system.tag.writeBlocking(["[.]Y_Max"], [current_y])

```

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 12, 2024, 6:38pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205/2 "2024-03-12T18:38:12Z")

</div>

You could combine your tags into a single expression tag:

```auto
max({tag1},
  {tag2},
  ....
  {tag24})

```

Then you can just worry about tracking the highest value of that over time.  
You may also want to look into this module:

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934/1):
>
> Automation Professionals is pleased to announce the immediately availability of a major upgrade to its free Simulation Aids Integration Toolkit module. The new feature justifying the "major upgrade" language is the implementation of eleven thirty-one new expression functions which use iteration to accomplish complex transforms of datasets and lists, to or from other datasets and lists, applying filtering, ordering, and computed new columns along the way. While there are certain operations that…

It's got some powerful tools that could make this a bit more efficient.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 12, 2024, 7:59pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205/3 "2024-03-12T19:59:42Z")

</div>

For fun, I decided to implement this using the abovementioned module. I split it into two tags for readability but there's nothing stopping you from nesting the expressions into a single monstrosity:

Tag 1, getting the highest tag value of our group (assuming the tags are nicely ordered and 1-indexed):

```auto
max(
	forEach(
		tags(
			forEach(24, stringFormat("[default]path/to/tag_%d", idx()+1))
		),
	it()[1]
	)
)

```

Tag 2, getting the max of Tag 1 over time (see [Tag Max Value no SQL - #2 by pturmel](https://forum.inductiveautomation.com/t/tag-max-value-no-sql/35649/2))

```auto
objectscript("args[0] if state.get('max') is None or args[0]>state.get('max') else state.get('max')\nstate['max']=__retv",
	{[~]Tag_1})[0]

```

---

<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:** [March 12, 2024, 8:24pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205/4 "2024-03-12T20:24:30Z")

</div>

> [@Felipe\_CRM](#):
>
> expressions into a single monstrosity:

It's best if the part _ **inside** _ the `tags()` expression is just a property reference. The part outside can be a monstrosity. 😁

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [March 12, 2024, 8:28pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205/5 "2024-03-12T20:28:26Z")

</div>

So it would be better to have the `forEach(24, stringFormat("[default]path/to/tag_%d", idx()+1)` in its own custom prop/tag and then reference that in the first expression?

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [March 12, 2024, 8:36pm UTC](https://forum.inductiveautomation.com/t/perspective-working-with-tags-using-script/87205/6 "2024-03-12T20:36:20Z")

</div>

Thank you, the max syntax works very well.
