I have a history enabled tag, I am attempting to write a script to print the value the tag has currently, as well as the value it had earlier in the day. However, the value for earlier always is returned as "None" though I am certain there is data available. The code I am using is as follows
You aren't passing a tag path to your history query, but the result of the readBlocking--a list of QVs. So the history query will look up the stringified version of that list as though it is a tag path, and won't find it, yielding null. (Look at the column name for that in the history dataset to see what I mean.)
Don't use the variable name tagpath for something that isn't a tag path.
history = system.tag.queryTagHistory("[default]CWS Retail/Bag Check Weigh - Line 5/Statistics/Current/Batch/Total Accepted Count"), startDate = , endDate =
And that should get me the actual value of the tag?
Also my apologies, I thought it was good practice to define tag paths like I did above, is that true for cases other than this or just generally not true to do so?
Okay yep changed that and it now works as expected, thank you.
I think I was erroneously following the docs for system.tag.queryTagCalculations where I mistook it using system.tag.queryTagCalculations(paths=['Historical Tag']
Potentially dumb followup here, I can now simply write this value to a new tag using system.tag.writeBlocking([path],[oldvalue]) and then enable history on it right?