Insert dateValue into MSSQL field with Data Type of "date"

Traceback (innermost last):
File “event:actionPerformed”, line 8, in ?
NameError: Ticket_Date

at org.python.core.Py.NameError(Py.java)
at org.python.core.PyFrame.getglobal(PyFrame.java)
at org.python.core.PyFrame.getname(PyFrame.java)
at org.python.pycode._pyx1.f$0(<event:actionPerformed>:8)
at org.python.pycode._pyx1.call_function(<event:actionPerformed>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:394)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:139)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:247)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at $Proxy1.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.2.8 (b178)
Java: Sun Microsystems Inc. 1.6.0_26

Produced from:

UID = event.source.parent.getComponent("UID_tb").text
TDate = event.source.parent.getComponent("TicketDate").dateValue
Email = event.source.parent.getComponent("Email_tb").text
Phone = event.source.parent.getComponent("Phone_tb").text
Priority = event.source.parent.getComponent("Priority_tb").intValue
Description = event.source.parent.getComponent("Description_ta").text

system.db.runPrepUpdate("INSERT INTO tbl_Ticket (UID, TDate, Email, Phone, Priority, Description) VALUES (?,?,?,?,?,?)", [UID, Ticket_Date, Email, Phone, Priority, Description])
system.gui.messageBox("Request added")

MSSQL tbl_Ticket:

ID	                int
UID	                varchar(50)
Ticket_Date	date
Email	                varchar(50)
Phone	        varchar(50)
Priority	        int
Description        varchar(MAX)

It is not a MSSQL problem. Whenever you get a NameError from a script it means the variable was not initialized. Instead of Ticket_Date you have TDate. Change the code to the following:[code]UID = event.source.parent.getComponent(“UID_tb”).text
TDate = event.source.parent.getComponent(“TicketDate”).dateValue
Email = event.source.parent.getComponent(“Email_tb”).text
Phone = event.source.parent.getComponent(“Phone_tb”).text
Priority = event.source.parent.getComponent(“Priority_tb”).intValue
Description = event.source.parent.getComponent(“Description_ta”).text

system.db.runPrepUpdate(“INSERT INTO tbl_Ticket (UID, TDate, Email, Phone, Priority, Description) VALUES (?,?,?,?,?,?)”, [UID, TDate, Email, Phone, Priority, Description])
system.gui.messageBox(“Request added”)[/code]Note the end [UID, TDate not [UID, Ticket_Date.

This did help.

I was not understanding where the variables from the script were being passed to the actual field names.

Now if I only knew a way to write a script once and reference it everywhere :thumb_right: :thumb_left:

I like how the formatting is automatic. no mater what I pass dateValue to (date, smalldate, time(7), datetime), it is automatically formatted.

Perhaps you mean project script modules?

Regards,

Excellent. So do all the noobs post as much as I am? I can see much more coming.

ecujak - Keep it up!!!

I did notice the tab strip post that you deleted earlier. Did you get it figured out? Are you using the tab strip customizer? It’s pretty snazzy.

Well, it would be better for them if they did, I suppose…

From our side, it’s useful. We have a bit of a rule, until we can answer all basic questions with a reference to the User Manual, the user manual isn’t good enough yet! :laughing:

And of course, we’re always talking about what we can do to help beginners get going… tweaking features, new videos, tutorials, etc. We’re going to try to ramp up the production of those things soon.

As Nathan said, keep it up!

Regards,

I know this originated as an HMI/MES/SCADA. My controller guy is moving along nicely. I was trying to consolidate some other smaller data entry and reporting tools. My friend showed me that ignition could to more than just visualize and control our controllers. I plan to slowly use ignition as my one tool to rule them all. I am sure I am going to force some square pegs into some round holes.

About the manual and videos… it is all there it seems. If you could break items down into smaller how-to style work steps, It would be easier to pick up. I am not promoting M$, but check out their asp.net learning site. http://www.asp.net/mvc

That is nice how they organize their tutorials with screenshots. I’ve been tossing around the idea of creating smaller (2 minute) videos that illustrate specific how-to examples that use text in bubbles instead of a voice overlay.

I’m glad you’re finding a wide range of uses for Ignition. You might consider signing up for a training course. That’s a sure way to learn a whole lot in a short period of time.

Perhaps you mean project script modules?

Regards,[/quote]

Using the Script Modules, how can I code once something like the example in your cellEdited script of your Editable Table example. How would I define this in the Script Module Editor and how would I call this? What parameters should be included? I tried something like the code shown below, but I couldn’t get this to work. Please help.

    app.myFuncs.cellEdited(event)

Is there a repository of helpful script modules contributed by the community?

That would be the correct way of calling the global script function:app.myFuncs.cellEdited(event)on the cellEdited event of the table. Now you just have to create the function definition in the script modules. In the designer select Project > Script Modules. There make sure to add a module called myFuncs under app. Once it is added select the myFuncs module and the code will look something like:def cellEdited(event, idCol="id"): import system cols = ["id", "col1", "col2"] row = event.row col = event.column column = cols[col] value = event.newValue data = event.source.data id = data.getValueAt(row, idCol) system.db.runPrepUpdate("UPDATE table SET %s = ? WHERE id = ?" % column, [value, id])Hope this helps.