-
I am trying to pass an initial value for a DateTimePicker as a parameter to a popup window. The date parameter is obtained from a SQL query.
-
I bound a label in the pop up window to the date parameter and that works fine. It is formatted as: May 1, 2022, 6:00:37 PM
-
The DateTimePicker components value is bound to the date parameter (Expression {view.params.commit_date} )This is not working (the component displays the current date/time)
-
I have a button that writes the DateTimePicker value to the SQL table queried in (1). This works fine. So in step 1 I am reading the data written to SQL by the button script (the DateTimePicker value)
-
I noticed that when I write picker value to the view date parameter in the same script (4) the format is changed to: “2022-05-01T22:00:37.510Z”
So I am theorizing that in step 1 I need to reformat the date parameter? From the testing I have done everything is type java.util.Date, so there
shouldn’t be a conflict there.
Ignition documentation states the value property is value:dropdown. Do I need to reformat the datetime for that???
Ignition version is 8.06
Thanks!!!
It looks like this is an issue with passing the date to a view parameter and binding the component to the parameter.
It works fine when I changed the button script to write the date to a tag before opening the popup, and binding the component to the tag.
I don’t really like this approach as multiple people could be performing updates at the same time overwriting the date field.
Don’t write it to a tag. Make a bidirectonal binding to a sesson variable. That way it will only affect the one client.
- On the Project Browser select Perspective.
- In the Property Editor go down to the Session Custom section and add a custom property. Call it
selectedDate
or whatever you like.
- Bind the DateTimePicker value to the custom session variable. Make sure it’s bidirectional.
- Bind everything that needs it to the session variable.
This is a handy way to, for example, put the date picker in the page banner and have it useable by all the views.
Thanks! I was thinking there must be some functionality like this.
I solved my issue by binding the date picker to a query (instead of running the query on the button action and passing the result as a parameter). The advantage to my first approach is I could pull values for multiple components with one query and pass them as parameters. Now I am binding each component to it’s own query.
I want to try your idea, it seems much cleaner.
I had some problem, I was trying to write in the value a string. I had to use system.date.parse(selected_data["start"], "yyyy-MM-dd HH:mm:ss") to convert from String to DateTime format.
You should always use datetime datatypes within the application until you need to convert it to human-readable format.