Get name from folder in Tag Browser

Hi everyone,

I have a some naming conventions associated with how I built my folder hierarchy in the tag browser and I was wondering if you could get to folder names through expressions.

Hopefully the attached pic helps show what I want to do. In it, I have a data type called Test_Machine. Instead of giving that datatype Line_ID and Machine_ID parameters that I have to type in myself for every instance, I want them to have expression properties whose values come from the number at the end of the parent and parent’s parent folder. This way, simply creating a data type in a particular location would be enough for it to describe itself. So if you read down, the current null values would be:

1
1

1
2

1
3

Thanks in advance,
Steve

This thread should get you started

inductiveautomation.com/forum/v … lit=+parse

Hi,

Thanks for the reply. I saw that thread when cruising the forum before posting and unless I missed something (quite possible!) I don’t think it’s what I’m after.

You have a tag path hard-coded and then correctly state there are a million ways to parse strings. But how could I get that string dynamically based on where my data type instance is? I want an expression tag in my Test_Machine data type that would display the values “Test_Machine_1”, “Test_Line_1”, “Test_Machine_2”, “Test_Line_1”, etc. but don’t know if the text from folders is accessible.

If it’s possible I’d then need to use the Expression language and not Python. I don’t think that would be a problem with either Strings expression functions or runScript and will cross that bridge if I get to it.

if you are using templates and UDT then there is a tag folder on the UDT called META, that contains the Tag Name and Tag Path.

[attachment=0]UDTMeta.PNG[/attachment]

That’s the data I’m after but it wouldn’t just be in templates. I would be using these tags in other places like transaction groups.

It’s not the end of the world if it can’t be done. I have the opportunity to start with a clean slate on a new project and thought this would be better than what I’m currently doing which is overwriting a memory tag for each instance of a UDT.

I just had a play with this to see if I could so it, it should be easy to get the tagpath of a tag, but its not. Its not a tag attribute and there is no expression to retrieve it. Interesting, perhaps its a good candidate for a suggestion, it could be very useful.

Thanks for the sanity check. I too thought it would be easy and I was just missing something obvious :scratch:

This post is LONG overdue, but a forum search led me here, so posting my results for future inquiries.

Regarding (non-UDT) relative tag referencing, you should be able to get the name of a tag (folder) by adding a suffix of ".Name" to your tag path.
For example, if you wanted to grab the value of tag within a specific tag provider (of which happens to have the same name as the parent folder this new expression tag resides in), the following expression should work:

tag("[" + {[.].Name} + "]" + "Path/To/Tag")

If utilizing UDTs, a better option might be to utilize built-in parameters of UDTs: {InstanceName}, {PathToParentFolder}, etc.

Edit: Updated case (.Name vs .name)

I ran into this problem... any ideas on how to find the name of the parent parent folder?

If you mean, you want a tag to contain the value matching the name of the grandparent folder.... I admit, I thought that task would have been easier...

Some helpful docs on relative referencing within expressions:
https://docs.inductiveautomation.com/display/DOC81/Tag+Paths

From within an expression tag:
{[.].Path} = Returns [provider]path/to/parent folder

And, while: {[.]..} = Grandparent folder (obtained by 'insert tag' then clicking on parent parent folder)...
I was unable to figure out a way to get the name of said-folder without string manipulation on the {[.].Path} string.
For example, path of grandparent folder might resemble:

left({[.].Path},lastIndexOf(toString({[.].Path}),"/"))

Or, you can access the name of any of the parent folders from a dataset tag containing the following expression:

split({[.].Path},'/')

Or, extracting the grandparent folder name only (from above dataset) in a string expression tag:

split({[.].Path},'/')[(len(split({[.].Path},'/'))-2),0]

Where len(x)-1 = parent, len(x)-2 = grandparent, etc.
Unfortunately, nothing I found was terribly elegant... perhaps others can chime-in.

Edit: Updated case (.Path vs .path)

first, thank you a lot.

but this becomes very hard to maintain!!!!

The fundamental problem is a tag hierarchy and/or UI structure that requires you to know the parent path. Instead:

  • Pass folder names (including UDT instances) as "tagPath' parameters wherever you will do indirect binding.

  • Concatenate /someInnerName and/or .somePropName in indirect bindings and when supplying tag paths to nested UI elements.

  • Use ../ relative names only within a single UDT where an element in the UDT is referencing something else in the same UDT. If you need relative paths anywhere else, you've screwed up. (Or somebody has.)

Hi Phil,
thanks ... at the origin, my idea was about an alarm ... for example in the "Label" put a parent parent folder name just because my tag hierarchy is almost like:
ZZZZ/ALM/alm00
where
ZZZZ: is my Zone name
ALM: a folder with zone alarms...
alm00: a tag with the alarms
so it would be great if I could link the parent-parent folder name.
Just looking for an elegant way or a way that I do not need to write too much code :slight_smile: because i normally lazy.

It would be handy to utilize a UDT for this...if possible.
Would you be able to share a screenshot of your current tag structure, and perhaps some details of sample alarm descriptions, etc?