I have a stored procedure that returns an integer, just a sum of numbers. The named query (scalar) calls this SP, sends a datetime to filter the results. Testing the named query, I get the correct integer for the current datetime.
I create a custom prop and bind to that query, and get a conversion error if I send a now() value. Error converting datetime2 to datetime. So I used dateFormat(now(), 'yyyy/MM/dd hh:m:ss'), same error.
The actual value of the datetime must be like this for SQL Server to accept: '2024-07-31 10:54:01'. What could/should I do with now() to get what I need?
How do I determine the Java version? Looks like the Java JRE is built into Ignition, and is maintained by the IA devs. So, I should be able to try the jre11 driver and see if that helps. If anything breaks, though... I'll copy the current jre driver, just in case.
The error is the datetime2 conversion I mentioned earlier. The binding for this.custom.now is this: dateFormat(now(), 'yyyy/MM/dd hh:mm:ss').
The commented datetime in the Value field was a successful test.
Using the Scripting Tool, system.date.now() is a java.util.date object. If I print that out, I get: Wed Jul 31 15:34:05 PDT 2024 .
If I send that to the SAME query used in the binding, I get the expected integer returned!
I am missing something here in the expression language versus Jython. A simple cast, convert, format???
I found this thread:
Not sure how Transistor's code worked with the 0 in the now(0). I kept getting errors. So I adapted r123's code to fit my widget, removed the binding on this.custom.now and that seems to work.
I just don't understand why now() will not work in an expression binding for a named query datetime parameter, but system.date.now() will.
As I mentioned earlier, passing this string to a NQ does not work, when the query is expecting a datetime value. And Phil stresses that emphatically in his following post,