Tag history on a table

I have a table and its data accessed through tag history with selected historical tag. t_stamp for each of this tag is automatically pulled in to the table and I would like to limit the t_stamp to be less than now() or the current date. Because, historian wont be having any tag value that is greater than now(). How do I do that? Currently, I have two spinner with start date and end date which filter the table data between the selected date, but it will not restrict me to select the date which is greater than todays date.
Any idea to overcome this situation?

maybe try a property change script on the spinner and check if the selected date is > than now() and if it is then write the date to now()

1 Like

python scripting will not accept this now() for system timeā€¦
I know the below script is not correct , please do share how to write the script in event handlerā€¦

if (event.source.parent.getComponent(ā€˜EndDateā€™).dateValue)=> now():
EndDate= now()
Is this syntax correct for this? note:- EndDate is the name of the spinner.

Hi,

the now() function in python scripting should be called like this system.date.now().
Fore mor info see: https://docs.inductiveautomation.com/display/DOC79/system.date.now

2 Likes

Hello Jasko, thanks for the reply.
Some reason it is not accepting the script that I wrote. I gives an error mismatched input INDENT ā€¦
(note:- ENdDate is the name of the spinner)

what is wrong with the scriptā€¦can any one help me on thisā€¦

if(event.source.parent.getComponent(ā€˜EndDateā€™).dateValue > system.date.now()):
event.source.parent.getComponent(ā€˜EndDateā€™).dateValue=system.date.now()

Still learning this scriptā€¦

The line after your ā€˜ifā€™ statement has to be indented. White space matters in Python.

I canā€™t tell how your script is formatted because it gets mangled by the forum unless you type 3 back quote characters (`) on the line before the script, and 3 again after.

Hereā€™s how it should look. I also made a minor adjustment to eliminate calling getComponent() 2 times.

dateSelector = event.source.parent.getComponent('EndDate')
if dateSelector.dateValue > system.date.now():
	dateSelector.dateValue=system.date.now()
2 Likes

I'm not sure if its from copying the data over or if its the error, but make sure to indent the second line. The scripts use tabs/indents instead of brackets for nested code.

1 Like

Johson, Thanks for the reply and I ran with your script and is giving another error called no date attribute!!!
My date format is
Dec 6, 2018 7:02 AM and here is my code
dateSelector = event.source.parent.getComponent(ā€˜EndDateā€™)
if dateSelector.dateValue > system.date.now():
dateSelector.date=system.date.now()

Traceback (most recent call last):
File ā€œevent:actionPerformedā€, line 2, in
AttributeError: ā€˜com.inductiveautomation.ignition.common.script.Scrā€™ object has no attribute ā€˜dateā€™

some reason, system.date.now() is not accepting!!!

When posting script on the forum please include 3 back quotes on a line before your script and again after your script. This will preserve your formatting and make it more readable.

The error is not caused by calling system.date.now. 

dateSelector = event.source.parent.getComponent(ā€˜EndDateā€™)
if dateSelector.dateValue > system.date.now():
dateSelector.date=system.date.now()

On the 2nd line you are checking the attribute "dateValue" of the date selector component, but on the 3rd line you are trying to assign system.date.now() to an attribute named "date", which does not exist.

Look carefully at the script that I posted earlier and you can see that it is different than the one you posted.
1 Like

Thanks JGā€¦ I was using spinner as well as Date picker. One of them has dateValue and the other one has date and property. Probably that would have caused the issue. Any ways, I simply overcome this issue through an expression with out any script and working fineā€¦ Thanks to all for the helpā€¦