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

**URL:** <https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351>\
**Category:** Ignition\
**Created:** [September 28, 2011, 12:38pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351 "2011-09-28T12:38:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [September 28, 2011, 12:38pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/1 "2011-09-28T12:38:14Z")

</div>

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:

```auto
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:

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

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [September 28, 2011, 2:42pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/2 "2011-09-28T14:42:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [September 28, 2011, 3:51pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/3 "2011-09-28T15:51:37Z")

</div>

This did help.

> [@](#):
>
> system.db.runPrepUpdate("INSERT INTO Ticket (UID, Ticket\_Date, Email, Phone, Priority, Description, Ticket\_Time) VALUES (?,?,?,?,?,?,?)", [UID, TDate, Email, Phone, Priority, Description, TDate])

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:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:") ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [September 28, 2011, 3:57pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/4 "2011-09-28T15:57:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [September 28, 2011, 8:43pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/5 "2011-09-28T20:43:16Z")

</div>

> [@](#):
>
> Now if I only knew a way to write a script once and reference it everywhere

Perhaps you mean [project script modules](http://www.inductiveautomation.com/support/usermanuals/ignition/script_modules.htm)?

Regards,

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [September 29, 2011, 2:21pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/6 "2011-09-29T14:21:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [September 29, 2011, 2:39pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/7 "2011-09-29T14:39:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colby.Clegg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/colby.clegg/32/3282_2.png) [@Colby.Clegg](https://forum.inductiveautomation.com/u/Colby.Clegg)\
**Post date:** [September 29, 2011, 4:29pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/8 "2011-09-29T16:29:24Z")

</div>

> [@](#):
>
> do all the noobs post as much as I am

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! 😆

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,

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [September 29, 2011, 10:05pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/9 "2011-09-29T22:05:28Z")

</div>

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](http://asp.net) learning site. [http://www.asp.net/mvc](http://www.asp.net/mvc)

---

<div class="post-metadata">

**Author:** ![nathan](https://avatars.discourse-cdn.com/v4/letter/n/c5a1d2/32.png) [@nathan](https://forum.inductiveautomation.com/u/nathan)\
**Post date:** [September 30, 2011, 1:46pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/10 "2011-09-30T13:46:18Z")

</div>

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](http://www.inductiveautomation.com/pricing/support). That’s a sure way to learn a whole lot in a short period of time.

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [October 4, 2011, 4:06pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/11 "2011-10-04T16:06:43Z")

</div>

> [@Colby.Clegg](#):
>
> [quote]Now if I only knew a way to write a script once and reference it everywhere

Perhaps you mean [project script modules](http://www.inductiveautomation.com/support/usermanuals/ignition/script_modules.htm)?

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.

```auto
    app.myFuncs.cellEdited(event)
```

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

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [October 4, 2011, 5:15pm UTC](https://forum.inductiveautomation.com/t/insert-datevalue-into-mssql-field-with-data-type-of-date/3351/12 "2011-10-04T17:15:21Z")

</div>

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.
