# Search for a tag name through a script

**URL:** <https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [January 26, 2020, 11:48pm UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632 "2020-01-26T23:48:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 26, 2020, 11:48pm UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/1 "2020-01-26T23:48:05Z")

</div>

Is there a way to search for a tag name through an expression or a script that can drop a true or false if it exist or it doesn’t

---

<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:** [January 27, 2020, 12:05am UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/2 "2020-01-27T00:05:24Z")

</div>

You can use `system.tag.exists()` (from memory)

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 27, 2020, 1:34am UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/3 "2020-01-27T01:34:05Z")

</div>

I’m trying like this with a existing tag but didn’t work

```auto
if system.tag.exists("FE-301_Flow"):
	from java.awt import Color 
	event.source.fillPaint = Color(187,187,187)
else:
	from java.awt import Color 
	event.source.fillPaint = Color(187,0,255)

```

and this shows an error at the line: if system.tag.exists(“FE-301\_Flow”)\*\*\*(from memory):\*\*\*  
(from memory)

then I read that we have to add the provider name but nothing happen  
if system.tag.exists("[default]FE-301\_Flow"):

---

<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:** [January 27, 2020, 3:02am UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/4 "2020-01-27T03:02:20Z")

</div>

Is that the full tag path to the tag? Are you not using a folder structure?  
Also, the system library comes from the scripting framework, it looks like you’re trying to use this in an expression? I think you’re mixing up the expression language with the scripting language (jython), as you’re also using colons which are again a jython thing.

In expressions, you could read the quality of the tag and check if it’s “Not Found”. You’ll need to cast the quality to a string to compare it.  
`toStr({tag.quality}) = "Not Found"`

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [January 27, 2020, 3:28pm UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/5 "2020-01-27T15:28:30Z")

</div>

Look at the last post in this thread,

> [@How to tell if a tag exists](http://forum.inductiveautomation.com/t/how-to-tell-if-a-tag-exists/3899/9):
>
> Yeah, we should really have a tagExists expression function that returns 0 or 1 and never errors out. I will add a ticket into our system. Is this still not available?

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 28, 2020, 8:42pm UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/6 "2020-01-28T20:42:21Z")

</div>

> [@nminchin](#):
>
> toStr({tag.quality}) = "Not Found"

It is an script and it's just a rectangle that changes color if it exist or it doesn't exist

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7f8a78c57a25c7f018b7dee5db0803900f43ad80.png)

---

<div class="post-metadata">

**Author:** ![gzarate](https://avatars.discourse-cdn.com/v4/letter/g/ba8739/32.png) [@gzarate](https://forum.inductiveautomation.com/u/gzarate)\
**Post date:** [January 28, 2020, 8:45pm UTC](https://forum.inductiveautomation.com/t/search-for-a-tag-name-through-a-script/31632/7 "2020-01-28T20:45:31Z")

</div>

Also I did try the other way through an expression with a label that changes the text base on  
if the tag exist or it doesn’t, but the answer of it says it always exist

```auto
if (toStr({[default]nonexist.Quality}) = "Not Found","Do not exist","Does exist")

```

well guys I found this it was just a little error on what we where looking for “not found”  
the text that it drops its Bad\_NotFound  
and this works perfect!  
tag = B5/TESTING/A\_Value

```auto
if (toStr({B5/TESTING/A_Value.Quality}) = "Bad_NotFound","Do not exist","Does exist")  

```

Thanks for help to everyone
