Not sure what to ask here

I have a project that I have created for my coordinators to use and there seems to be a random issue popping up. The coordinators enter the data correctly but not all of it is going into the database. Only some of it is. The tags involved are all client scoped tags. Each person(at different times) selects a shift button, a department button, and enters in their info into the text fields under the SQDCME letters. What is happening is that some times all the information shows up in the database and sometimes the Department does not show up or the shift does not show up. And I can’t understand why. Can I get some suggestions of what to check?

Without seeing any code, it will be difficult to tell what’s going on. :slight_smile:

if system.gui.confirm("Have you selected and entered all the appropriate information?", "Are you sure?", 0):
	AreaSelected = event.source.parent.getComponent('AreaSelected').text
	ShiftSelected = event.source.parent.getComponent('ShiftSelected').text
	Stextfield = event.source.parent.getComponent('Stextfield').text
	Qtextfield = event.source.parent.getComponent('Qtextfield').text
	Dtextfield = event.source.parent.getComponent('Dtextfield').text
	Ctextfield = event.source.parent.getComponent('Ctextfield').text
	Mtextfield = event.source.parent.getComponent('Mtextfield').text
	Etextfield = event.source.parent.getComponent('Etextfield').text
	ProductionDate = event.source.parent.getComponent('ProductionDate').text
	Loggedin = event.source.parent.getComponent('LoginLabel').text

	query = "INSERT INTO SQDCME.dbo.SQDCME (t_stamp, Shift, Area, Safety, Quality, Delivery, Cost, Moral, Environment, Coordinator) VALUES (?,?,?,?,?,?,?,?,?,?)"
	args = [ProductionDate, ShiftSelected, AreaSelected, Stextfield, Qtextfield, Dtextfield, Ctextfield, Mtextfield, Etextfield, Loggedin]

	system.gui.messageBox("User canceled the update.", "Update Canceled")

value = 0
system.tag.write("[Client]SQDCME/AreaSelected", value)
system.tag.write("[Client]SQDCME/ShiftSelected", value)
system.tag.write("[Client]SQDCME/Shift_1", value)
system.tag.write("[Client]SQDCME/Shift_2", value)
system.tag.write("[Client]SQDCME/Shift_3", value)
system.tag.write("[Client]SQDCME/Stacker_1", value)
system.tag.write("[Client]SQDCME/Stacker_2", value)
system.tag.write("[Client]SQDCME/GreenLine", value)
system.tag.write("[Client]SQDCME/BlueLine", value)
system.tag.write("[Client]SQDCME/RoughMill", value)
system.tag.write("[Client]SQDCME/Janitorial", value)
system.tag.write("[Client]SQDCME/LumberDrying", value)
system.tag.write("[Client]SQDCME/ForkLifts", value)
system.tag.write("[Client]SQDCME/Finish", value)
system.tag.write("[Client]SQDCME/Maintenance", value)
system.tag.write("[Client]SQDCME/PX", value)
system.tag.write("[Client]SQDCME/Boilers", value)
system.tag.write("[Client]SQDCME/Autodefecting", value)
system.tag.write("[Client]SQDCME/Offline", value)
system.tag.write("[Client]SQDCME/Training", value)
event.source.parent.getComponent('Stextfield').intValue = 0
event.source.parent.getComponent('Qtextfield').intValue = 0
event.source.parent.getComponent('Dtextfield').intValue = 0
event.source.parent.getComponent('Ctextfield').intValue = 0
event.source.parent.getComponent('Mtextfield').intValue = 0
event.source.parent.getComponent('Etextfield').intValue = 0
event.source.parent.getComponent('Dtextfield').visible = 1
event.source.parent.getComponent('Container').getComponent('Dtank').visible = 1
event.source.parent.getComponent('Dgoaltextfield').visible = 1

This is the code from the submit button

SQDCME.proj (59.5 KB)

Are the text fields set to ‘Commit on Focus Loss’? If you directly go from entering a value in a text field to clicking the submit button, and they aren’t set to commit on focus loss, your script might be firing before the new value has been “confirmed” in the text field - so your script is getting old values.
You could also try just using print statements for all your values - then if someone notices an issue, you can go back to when they submitted and see what values were read from the components.

Each button basically puts a word into the AreaSelected client tag(string) detailing which one has been pushed. So if the stacker 1 button is pushed it puts the word “stacker1” into the string tag. And then the script from the submit button is “reading” that tag and dropping it into the database. Here is a sample:
This is the stacker 1 button:

Why are you doing it with mouseClicked instead of actionPerformed? I would bet on that being your issue. The actionPerformed covers all the different ways a button can be triggered. actionPerformed is the right place to control any actions a button needs to do. Where it looks like you already have a script in the actionPerformed section, I would switch to the Script Editor tab and copy the script that it created for your tag write then paste it into your actionPerformed script.

On a side note from your script above, the script would be more efficient if you used system.tag.writeAll() instead of individual system.tag.write()'s.


I did it this way because it was the only way I learned how, and I learned it by clicking and trying things.

I can understand that, but chances are the mouseClicked is what is causing your issues. I would suggest moving it to the actionPerformed section. Like I said though, it is as simple as clicking on the script editor tab, it generates the script for you, so you can copy and paste it into the same section in the actionPerformed. I’d try that and see if it solves your issue.

I also hope you don’t take this the wrong way but I’m also curious if you gain anything by storing the values in client tags. You can do the same thing writing to a custom property on the screen then have your script, that does your prepUpdate, pull from the custom property. If that would work for your needs, then it would remove the tag writes since then you would just send a value to a property. If the values are used on another screen then the client tags may be needed.

Edit: Thought about my question while looking again and realized I was mixing up the order of what your doing in my head, you already are pulling from properties of objects so my note probably isn’t relevant since your writing after that.

I did on the shift 1 button and it is working… Now that I know this, I am going to go back and redo the programming to see if this is the issue. I pray it’s that simple… Thank you!!

if system.gui.confirm("Have you selected and entered all the appropriate information?", "Are you sure?", 0):
    ProductionDate = event.source.parent.getComponent('ProductionDate').text
    if ProductionDate == '':
	    system.gui.messageBox('ProductionDate is empty')
    ShiftSelected = event.source.parent.getComponent('ShiftSelected').text
    if ShiftSelected == '':
	    system.gui.messageBox('ShiftSelected is empty')
    AreaSelected = event.source.parent.getComponent('AreaSelected').text
    if AreaSelected == '':
	    system.gui.messageBox('AreaSelected is empty')
    Stextfield = event.source.parent.getComponent('Stextfield').text
    if Stextfield == '':
    	system.gui.messageBox('Stextfield is empty')
    Qtextfield = event.source.parent.getComponent('Qtextfield').text
    if Qtextfield == '':
	    system.gui.messageBox('Qtextfield is empty')
    Dtextfield = event.source.parent.getComponent('Dtextfield').text
    if Dtextfield == '':
	    system.gui.messageBox('Dtextfield is empty')
    Ctextfield = event.source.parent.getComponent('Ctextfield').text
    if Ctextfield == '':
	    system.gui.messageBox('Ctextfield is empty')
    Mtextfield = event.source.parent.getComponent('Mtextfield').text
    if Mtextfield == '':
	    system.gui.messageBox('Mtextfield is empty')
    Etextfield = event.source.parent.getComponent('Etextfield').text
    if Etextfield == '':
	    system.gui.messageBox('Etextfield is empty')
    Loggedin = event.source.parent.getComponent('LoginLabel').text
    if Loggedin == '':
	    system.gui.messageBox('Loggedin is empty')

    sql = "INSERT INTO SQDCME.dbo.SQDCME (t_stamp, Shift, Area, Safety, Quality, Delivery, Cost, Moral, Environment, Coordinator) VALUES (?,?,?,?,?,?,?,?,?,?)"
    args = [ProductionDate, ShiftSelected, AreaSelected, Stextfield, Qtextfield, Dtextfield, Ctextfield, Mtextfield, Etextfield, Loggedin]
    system.gui.messageBox("User canceled the update.", "Update Canceled")

event.source.parent.getComponent('AreaSelected').text = ''
event.source.parent.getComponent('ShiftSelected').text = ''
event.source.parent.getComponent('Stextfield').text = ''
event.source.parent.getComponent('Qtextfield').text = ''
event.source.parent.getComponent('Dtextfield').text = ''
event.source.parent.getComponent('Ctextfield').text = ''
event.source.parent.getComponent('Mtextfield').text = ''
event.source.parent.getComponent('Etextfield').text = ''
event.source.parent.getComponent('ProductionDate').text = ''
event.source.parent.getComponent('LoginLabel').text = ''

For a test run the following code on the submit button. It will check and tell you which values are going to be “empty”. It will then clear all the text values after submitting the text. Hit the button once, fill in all the info, hit the button a second time. Tell me/us what message boxes says the second time.

I agree with @bpreston. The mouseClicked event causes a LOT of headaches. Any cursor movement during the click will prevent the event from firing. You can see this if you press and hold, move your cursor just one pixel, and release - the mouseClicked event will not fire. But if you press and hold, keep the cursor on the same pixel, and release - the mouseClicked event will fire. So if anyone is quickly moving their cursor to click on the buttons, it is very likely that they will move their cursor at least a little bit during the clicking action - preventing the mouseClicked event from firing.

For buttons you definitely want to use actionPerformed. But for components that do not have an actionPerformed event, it is usually better to use mousePressed or mouseReleased (or both). You will find that they a lot more consistent, from a user experience perspective.