# Scripting help

**URL:** <https://forum.inductiveautomation.com/t/scripting-help/10626>\
**Category:** Ignition\
**Created:** [October 14, 2015, 9:56pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626 "2015-10-14T21:56:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jado58](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@Jado58](https://forum.inductiveautomation.com/u/Jado58)\
**Post date:** [October 14, 2015, 9:56pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/1 "2015-10-14T21:56:03Z")

</div>

I’m trying to insert date from pop up calendar using the following code on mouse click

```auto
queryValue2 =event.source.parent.getComponent('Popup Calendar').date,

system.db.runUpdateQuery("INSERT INTO wo_records (t_start) VALUES ([b]'%s'[/b])" % (queryValue2),getKey=1)
```

I believe I’m not using the correct modifier, any hints on what modifier I should use for data format?

the error code

[code]java.lang.Exception: java.lang.Exception: Error executing system.db.runUpdateQuery(INSERT INTO wo\_records (t\_start) VALUES (‘Wed Oct 14 15:41:24 CDT 2015’), , , true)

```
caused by Exception: Error executing system.db.runUpdateQuery(INSERT INTO wo_records (t_start) VALUES ('Wed Oct 14 15:41:24 CDT 2015'), , , true)
caused by GatewayException: SQL error for "INSERT INTO wo_records (t_start) VALUES ('Wed Oct 14 15:41:24 CDT 2015')": Conversion failed when converting date and/or time from character string.
caused by SQLServerException: Conversion failed when converting date and/or time from character string.

```

[/code]

Thank you

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [October 14, 2015, 10:40pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/2 "2015-10-14T22:40:10Z")

</div>

How about this:

`
queryValue2 =event.source.parent.getComponent('Popup Calendar').date
system.db.runPrepUpdate("INSERT INTO wo_records (t_start) VALUES (?)", [queryValue2],getKey=1)
`Best,

---

<div class="post-metadata">

**Author:** ![Jado58](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@Jado58](https://forum.inductiveautomation.com/u/Jado58)\
**Post date:** [October 15, 2015, 3:05pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/3 "2015-10-15T15:05:18Z")

</div>

[quote=“nmudge”]How about this:

```auto
queryValue2 =event.source.parent.getComponent('Popup Calendar').date
system.db.runPrepUpdate("INSERT INTO wo_records (t_start) VALUES (?)", [queryValue2],getKey=1)
[/code]Best,[/quote]
 Changing the .date to .text for the pop up calendar worked with what you suggested ,

Now I have 3 separate statement, that work independently , but Im not able to combine into one statement.
[code]queryValue1 = event.source.parent.getComponent('Numeric Text Field').intValue
queryValue2 =event.source.parent.getComponent('Popup Calendar').text
queryValue3 =event.source.parent.getComponent('Dropdown').selectedValue

system.db.runUpdateQuery("INSERT INTO wo_records (wo) VALUES ('%d')" % (queryValue1),getKey=1)
system.db.runUpdateQuery("INSERT INTO wo_records (get_address) VALUES ('%d')" % (queryValue3),getKey=1)
system.db.runPrepUpdate("INSERT INTO wo_records (t_start) VALUES (?)", [queryValue2],getKey=1)

```

when I combine the 2 INT it works fine

```auto
system.db.runUpdateQuery("INSERT INTO wo_records (wo,get_address) VALUES ('%d','%d')" % ((queryValue1),(queryValue3)),getKey=1)
```

and if add the time I get errorr (TypeError: int argument required)

```auto
system.db.runUpdateQuery("INSERT INTO wo_records (wo,t_start,get_address) VALUES ('%d','?','%d')" % ((queryValue1),(queryValue2),(queryValue3)),getKey=1)
```

any suggestions on this one?

Thanks!

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [October 15, 2015, 3:30pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/4 "2015-10-15T15:30:14Z")

</div>

Yes, don’t use the system.db.runUpdateQuery function. Instead use system.db.runPrepUpdate.

Example:

[code]  
queryValue1 = event.source.parent.getComponent(‘Numeric Text Field’).intValue  
queryValue2 =event.source.parent.getComponent(‘Popup Calendar’).text  
queryValue3 =event.source.parent.getComponent(‘Dropdown’).selectedValue

system.db.runPrepUpdate(“INSERT INTO wo\_records (wo,t\_start,get\_address) VALUES (?,?,?)”, [queryValue1,queryValue2,queryValue3],getKey=1)  
[/code]Best,

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 15, 2015, 3:43pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/5 "2015-10-15T15:43:25Z")

</div>

I was going to suggest changing the ‘?’ to ‘%s’ for a string. The problem is that you were trying to use two different syntaxes. Either Nick’s or my suggestion should work for you.

```auto
system.db.runUpdateQuery("INSERT INTO wo_records (wo,t_start,get_address) VALUES ('%d','%s','%d')" % (queryValue1, queryValue2 , queryValue3), getKey=1)
```

---

<div class="post-metadata">

**Author:** ![Jado58](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@Jado58](https://forum.inductiveautomation.com/u/Jado58)\
**Post date:** [October 15, 2015, 5:17pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/6 "2015-10-15T17:17:35Z")

</div>

Thank you both, Im and electrical engineer by degree and I’m still new to coding and ignition. both are helpful answers and I see where my errors are, Thank you!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 15, 2015, 6:36pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/7 "2015-10-15T18:36:46Z")

</div>

> [@Jado58](#):
>
> I'm an electrical engineer

Me too! Can't spell 'geek' without a EE, I always say! 😆

---

<div class="post-metadata">

**Author:** ![Jado58](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@Jado58](https://forum.inductiveautomation.com/u/Jado58)\
**Post date:** [October 16, 2015, 1:41pm UTC](https://forum.inductiveautomation.com/t/scripting-help/10626/8 "2015-10-16T13:41:48Z")

</div>

I haven’t heard of that one! I’m sure I’ll use it soon 😆
