Popup Calendar : Script Triggering

I’m attempted to have the date/time written to my SQL database when a value is entered in the popup calendar box. The way I accomplish this with Text Fields / Areas, is on “focus lost” it executes the script, this seems to be working in a satisfactory way.

The PopUp Calendar option does not have a FocusLost option. “Property Change” causes a lot of issues with running with updated values/running twice / generally undependable, however if i "sleep’ the several popup boxes for a couple seconds, results are consistent but the app is clunky.

I’m trying to find an eloquent way to update the script, the easiest way would be when the “OK” button is pressed to execute the Update/Insert SQL script but I do not know how to accomplish this (or if it is possible).

The other options, Mouse clicked/existed/released etc… do not deliver consistent updates.

any help/ thoughts appreciated.

Can you use the property change of the “date” property? That should be equivalent to using the “OK” button.

the prior issues i had w/ the date property, is these boxes are being used with multiple objects, and when an object is changed it triggers all of them, which causes a lot of lag.

I’m just selecting the “propertyChange” option in the Component Scripting, is there a command or line that i can add to specify the Date property being changed?

Have you tried adding

if event.propertyName == 'date':
     Your code here

Make sure date is lower case.

You can always print out the propertyNames to see how they return with different options using.

print event.propertyName

I’m not the best with coding… this is what I attempted to add, which isn’t quite doing anything:

if event.source.parent.getComponent(‘PopupCalendar’).date == ‘date’:
if checknull is None:

  	system.db.runPrepUpdate("INSERT INTO Table1 (column1, date) VALUES (?, ?)", [ID, celldata])

 	system.db.runPrepUpdate("UPDATE table1 SET date = ?  WHERE column1= ?", [celldata, >ID])

I wouldn’t use the sleep. I’m also not sure what your trying to do with the checknull. I’m assuming your trying to make sure the date isn’t null is so then your code would be. Is there a reason for the sleep or just using trying to get it to work?

if event.propertyName == ‘date’:
	if event.newValue:
		system.db.runPrepUpdate("UPDATE table1 SET date = ? WHERE column1= ?", [celldata, ID])
		system.db.runPrepUpdate("INSERT INTO Table1 (column1, date) VALUES (?, ?)", [ID, celldata])

That actually worked like a charm, the if event.propertyName == ‘date’. Thanks!

Date data is in a table of its own, with not all objects. The checknull is checking if there is the current object has data written in the date table, so it would use a update vs insert. That portion is working, I couldn’t quite figure out how to get event.newValue working.

Also, if the sleep isn’t there, it would run the update script twice on property change, so i’d get duplicate values in, I couldn’t figure out the best way to stop that, the sleep stopped that from happening, but it adds a lag I dislike, not sure how to stop that.

Thanks again for your help, if you have any suggestions with the other issues, would be readily and graciously applied.

Having everything inside of the event.propertyName == ‘date’ should have it only run once. But you would have to verify if it gets triggered when the page loads too. Thats where using

print event.propertyName

can be very useful. It lets you see what is triggering when the property changes then you can use what you see to set your filters for when the script actually runs. If inside of the event.propertyName == ‘date’ if statement you use event.newValue it should give you the new value for what is stored in the date property. I used it just as an if and that so if a value is present then it would complete what is inside of the if statement. You can also do

if event.newValue == None: 

This is the same as looking for a Null value in that property.

Using the sleep there shouldn’t stop it from running twice on a change. You cause a delay before the script can complete. It will also stop the user interface from responding while it is waiting for the sleep to finish. If you are still seeing it running multiple times what I would do is comment out your queries and the sleep. Then use print statements to help you figure out why it is triggering extra times. Something as simple as “print event.newValue” can let you see if the date is updating multiple times for some reason. If it is then I would assume you have something else writing back to that date picker. You would need to find what else is triggering the date picker and prevent it from doing that.

In case it doesn’t become obvious when you add print event.propertyName to the procedure, it is dangerous (to your UI) to do anything active in a propertyChange event that isn’t nested inside a check for the correct property name. You are likely to get recursive actions that freeze or horribly slow down your UI.

It is also bad to do any calls that need more than the most trivial round-trip to the gateway. If you can’t reliably execute an event in a tenth of a second, use invokeAsynchronous().

Ignition has a “Webinar” training video that shows exactly how this should be handled.

I use it on all my reports that require a Start/End selection. Works perfectly.

1 Like

Can you name the Webinar

I have several forms that I’m launching and I have a simple need for automatically writing the text in a text field to the database.

Right now i’m attempting to use the propertyChange field to accomplish this, starting with an “if event.propertyName == ‘text’:”,

but if the database does not have an entry for this object, i needs to “Insert”, i have an if statement for that, issue is, even with the even.propertyName if statement, it runs the insert statement twice, resulting in an error for ‘duplicate’ entry (I force unique in a column), I do not…quite understand where to add the invokeAsynchornous code

> if event.propertyName == "text":
> 	if ID is None:
> 		system.db.runPrepUpdate("INSERT INTO table (id1, column1) VALUES (?, ?)", [linkID, celldata])
> 	else:
> 		system.db.runPrepUpdate("UPDATE table SET column1= ?  WHERE id1= ?", [celldata, ID])

The code works fine, other than the insert command running twice, causing issues… I would love to be able to do this without adding a ‘sleep’ time to the form, as that adds a lot of lag.

I’m trying to go back and find it again, but I can’t locate. But it’s the video I followed which in turn made my reports come together with “Pop Up Calendar” and “Date” parameter.

Will continue to try to locate.

Here’s what I was talking about. Now just bind your Report Viewer “Startdate” and EndDate" to your PopUp Calendar Start and End values.

Passing Date Parameter in Report Sql Query