Deleting Tags From a Provider

I am using com.inductiveautomation.ignition.gateway.tags.model.GatewayTagManager#importTagsAsync to create tags directly and it is working great.

However if I import a folder that is already present, it doesn't remove any tags not present in the new import.



- Tag A
- Tag B


- Tag B
- Tag C

End Result:

- Tag A
- Tag B
- Tag C

My Desired Result:

- Tag B
- Tag C

Is it possible to achieve the desired output with the current importTagsAsync function I am using? Or do I need to delete the tags present first?

Secondly, what method should I be looking for to delete the tags? I have tried com.inductiveautomation.ignition.common.tags.model.TagProvider#removeTagConfigsAsync but it doesn't look like it's removing the tags.

I appreciate any info!

Have you tried a different collision policy? I don't know for sure, but I'd expect if your config defines MyFolder and you have Overwrite, you would, in theory, end up with your desired result?

If that doesn't work, I don't think there is a way to do this in a single operation.

Yeah I have been using Overwrite and it isn't doing what I am looking for. It is just overwriting instances of the tags present, not the folders and their contents.

If I need to do this in two operations, what would be the actual method needed to delete tags at all? The removeTagConfigAsync doesn't seem to be deleting the tags, even when it returns a quality of Good.

Some progress, it looks like removeTagConfigAsync may be the answer, and I am just doing something wrong.

When trying to delete the following path: [default]MyFolder I am getting the following error: Error("Cannot delete root node")

I have tried adding the / to the end of it as well for [default]MyFolder/ but I get the same issue.

I am wondering if in some way it's potentially because it's a folder?

EDIT: Doesn't seem to work even if I give it a path to an atomic tag.

How are you constructing your tagpath? I don't see a way to get that error with a valid, non-root tagpath.

Essentialy this:

TagPath folderPath = new BasicTagPath("[default]" + tagObject.get("name").toString().replaceAll("\"", ""));
List<QualityCode> deleteQualityCodes = tagProvider.removeTagConfigsAsync(List.of(folderPath)).join();

Where tagObject.get("name").toString() returns "MyFolder", but with the quotes, so I need to remove them.

Look closer at the constructor for BasicTagPath you're using. You're only passing a source argument; that's why it's not working.
You can either pass a source and a List, or you could use a static method from TagPathParser, or you could create a new BasicTagPath("default") and then call getChildPath(String), but whatever you do, the way you're doing it right now is wrong :slight_smile:

That was exactly the problem! Using getChildPath was the cleanest answer I think. Thank you

I have a very similar application, I am importing with system.tag.importTags(), but as stated above when a tag doesnt exist in the new set, it doesnt get deleted.

What would be the best approach? I want to delete all UDT definitions before importing the new ones.

system.tag.importTags(filePath, "[" + provider + "]_types_", "Overwrite")