History Tag Search and Export
If you have a lot of Tags storing history, it can be difficult to list them all out in the function above. This example makes things easier by specifying a folder of Tags instead of individual Tags. The script first grabs all of the historical Tags from a particular folder and gets the Tag paths using the system.tag.browseHistoricalTags function, runs those through the system.tag.queryTagHistory function, and then exports the results to a CSV file. This script is great, because it can be run from the scripting console, or from a button on the client. However, everything in the script is hardcoded to work with a specific system, though that can be easily changed to fit any system. Below are the list of parts that can be changed with what each of them is used for.
|Part of Script||Description|
The path to the parent folder that we are searching through for history Tags. Each part of the string corresponds to a different part of your system.
|This is what will actually query for historical data. While the path parameter should be kept the same, the other parameters can be altered to fit your needs. Currently, the function is querying the last 30 mins of history, has a return size of 10, an aggregation mode of Average, and a return format of wide. Of course, all of this can be changed. See system.tag.queryTagHistory for more information on the parameters that can be used here.|
|This is the path that the CSV file will save at. This can be changed to be any location you want. You can even use system.file.saveFile to first ask the user for a save location and filename, and then passing the path returned from that function into the writeFile function. The r at the beginning of the string is important as it allows us to not have to use double backslashes.|
This script can be dangerous! It recursively looks through a folder to find all historical Tags, and then uses all of those Tags to look up Tag history. Looking through a folder that has too many history Tags, or querying history for too large a period of time can potentially result in locking up your system. Use caution when using this function, and never search through too large a set of Tags or query too much history.