# \[FEATURE\] Add expression function to check if tag is valid (exists and not disabled)

**URL:** <https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192>\
**Category:** Ignition\
**Created:** [June 25, 2022, 1:07am UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192 "2022-06-25T01:07:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 25, 2022, 1:07am UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192/1 "2022-06-25T01:07:00Z")

</div>

I should have asked for this a _very_ long time ago to be honest…

I would like a function to check if a tag is valid. What I mean by this, is that it both exists and is not disabled. No other qualities should affect the value returned.

Often I will create templates / view templates that can accommodate multiple UDT definitions and/or instance configurations. E.g. differences in the tags available between similar UDT defs or tags that are disabled in particular instances of the UDTs. To accommodate these, I will check the quality of tags and hide the graphic component if the associated tag isn’t valid.

For these cases, currently I’m simply using `isGood()`, but technically this can be deceptive. If a tag is in fact valid for a UDT but has a configuration error for example, or is stale, waiting for initial value, etc. etc. then the graphic component using isGood will hide the display for it and essentially mask the issue, and will confuse the operator who is expecting to see the thing that is hidden.

The alternative currently is incredibly dopey and long-winded. I would have to do something like:

```auto
indexOf(toStr(qualityOf({tag})), 'Bad_NotFound') = -1 &&
indexOf(toStr(qualityOf({tag})), 'Bad_Disabled') = -1

```

I would like a new function explicitly for testing this, like `isValid` or similar so that I can just use:

```auto
isValid({tag})

```

Vote here:

> **[Add expression function to check if tag is valid (found and not disabled) |...](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/add-expression-function-to-check-if-tag-is-valid-found-and-not-disabled)**

I really wish I knew how to write my own module ☹

---

<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:** [June 25, 2022, 1:29am UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192/2 "2022-06-25T01:29:24Z")

</div>

Yes please. The two properties we want to confirm for the same reason are exists and enabled. `isGood` is great, but doesn't help with this use case.

> [@How to locate the number 'value' of a Tag's Data Quality](https://forum.inductiveautomation.com/t/how-to-locate-the-number-value-of-a-tags-data-quality/26840/15):
>
> In addition to an expression for tag exists, an expression for isDisabled would be great. We use the same UDTs on a lot of different ancient and modern PLCs (thank you for tag property overrides and scripted tag creation!) and disable unused UDT members that don’t exist in the older PLCs. Templates adapt based on whether members are disabled or not. Unfortunately we seem to be stuck with magic strings to make this happen. Alternatively, we could use the isGood expression if it weren’t for the f…

---

<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:** [June 25, 2022, 1:55am UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192/3 "2022-06-25T01:55:27Z")

</div>

`isValid({tag})` might imply more than exists and enabled.

`isEnabled({tag})` seems like a reasonable option. It would return false for disabled and false for doesn’t exist (can’t be enabled if it doesn’t exist).

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 25, 2022, 1:59am UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192/4 "2022-06-25T01:59:08Z")

</div>

Yeah, I agree that ‘valid’ isn’t quite right. I don’t think ‘enabled’ is either though 🤔

But I can’t think of anything else that I’d use that conveys both…

`existsAndEnabled`

---

<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 25, 2022, 1:10pm UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192/5 "2022-06-25T13:10:24Z")

</div>

How about `isAvailable()`?

Great idea by the way

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 21, 2023, 3:03am UTC](https://forum.inductiveautomation.com/t/feature-add-expression-function-to-check-if-tag-is-valid-exists-and-not-disabled/61192/6 "2023-08-21T03:03:44Z")

</div>

For posterity, this was added into Paul's Ignition Extensions module:

> [@Ignition Extensions - Convenience utilities for advanced users](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615):
>
> Introducing a hopefully community-engaged effort to build a useful repository of scripting and other Ignition utilities for everyone to benefit from. Download the latest release from the [Releases](https://github.com/IgnitionModuleDevelopmentCommunity/ignition-extensions/releases) page and take advantage of the following functions: Scripting Functions system.util system.util.getContext(): Context A convenience function to retrieve the local "context" object, useful as an entrypoint to other advanced scripting. system.util.deepCopy(object): Object Converts a given Pyth…

It would still be nice for this to be added into the product, since this will be unusable in Edge projects ☹
