Get List of UDTs Filtered on Parent Type

I have used system.tag.browse() to filter on a specific datatype, but I would like to be able to find all instances of a type and the instances of any child types that were created from that parent type.

For instance, if there was a UDT "motor" and a UDT "motor_speed" that used the motor UDT as the parent UDT type and added on a couple of tags, I want to get all instances of the motor and motor_speed UDTs in the same system.tag.browse() call, but I don't want to have to pass all of the child types because there may be other child types that exist as well.

And it might even go another UDT level deeper. The "motor_speed" UDT could also be a parent to "motor_speed2" and it should also be included in the browse.

Have you tried using the tag report tool?

If that can do it, you can have it export a script for the same search.

(Also the tag report tool script is way faster than system.tag.browse)

2 Likes

Thanks! The Ancestor filter option it was I was looking for.

Tag Path: *
Types: UDT Instance
Ancestor: types/motor

Copy as script produced this:

provider = 'default'
limit = 100

query = {
  "options": {
    "includeUdtMembers": False,
    "includeUdtDefinitions": False
  },
  "condition": {
    "path": "*",
    "hierarchy": {
      "typeId": "types/motor",
      "relationship": "SubType"
    },
    "tagType": "UdtInstance",
    "attributes": {
      "values": [],
      "requireAll": True
    }
  },
  "returnProperties": [
    "tagType",
    "quality"
  ]
}

# Limited to 100 rows. Use continuationPoint functionality to continue from last result, 
# or remove limit for full results.
results = system.tag.query(provider, query, limit)

print results

But results are in a PyWrapper. What do I do with that?

Also, can I do it with multiple providers at once, or am I going to have to use a loop with a list of providers?

One provider at a time I believe. But I've never tried to see if there's a way to do multiple.

Treat it like you would a system.tag.browse for the most part. Also note, you can add things to the return if there are specific field you'd like to get premade for you.. Add them in the right hand pane before you grab the script.

You’ll want to set this to True, although I'm not convinced that it will keep traversing nested UDT instances, but I could be wrong.. I’m not in a position to test at the moment myself.

To print the results I think you need to use

print results.results

Good point, although it doesn't necessarily apply to me right now. I know that these UDTs used inheritance rather than nesting.