# Script errot

**URL:** <https://forum.inductiveautomation.com/t/script-errot/9554>\
**Category:** 3rd Party Modules\
**Created:** [January 16, 2015, 5:56am UTC](https://forum.inductiveautomation.com/t/script-errot/9554 "2015-01-16T05:56:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Don\_t\_shoot](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Don\_t\_shoot](https://forum.inductiveautomation.com/u/Don_t_shoot)\
**Post date:** [January 16, 2015, 5:56am UTC](https://forum.inductiveautomation.com/t/script-errot/9554/1 "2015-01-16T05:56:12Z")

</div>

Thanks all the friends’s help . I want to do some script in a work order selector component and want all the workorder options in the component are showed in a time range we have selected a ‘starttime’ and a ‘endtime’. But it shows error ,and I try to change something ,it is also not work , so please help me to check the script , and the error for the reference as the pictures .Thanks !  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/29c2f0c7f967c054784f317751f500688a9b87b4.png)

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/bd89a3911251bf53d319de356b0a6c53a0538478.png)

---

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [January 16, 2015, 9:49am UTC](https://forum.inductiveautomation.com/t/script-errot/9554/2 "2015-01-16T09:49:53Z")

</div>

Just a guess, but the fact that Line 5 in your script is in purple suggests that maybe the string in Line 4 is not terminated.

Are you missing a double-quote (") symbol somewhere in Line 4?

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [January 16, 2015, 3:37pm UTC](https://forum.inductiveautomation.com/t/script-errot/9554/3 "2015-01-16T15:37:43Z")

</div>

When posting script to the forum for troubleshooting it is very helpful to copy and paste the script into your post and surround it with the code tags.

The easiest way to do it is to paste the script into the editor window, select all of the script using your mouse and then click on the “Code” button underneath the Subject line.

This will make it easier to spot errors and allow other users to paste the script into their projects to debug it without having to reformat it.

Using the code tags changes this:

import system  
from app import util  
event.source.running = 0   
sql\_conn = “SQL\_DB\_Name”  
sql\_query = (  
" SELECT TagName "  
" FROM SCADA\_Admin.dbo.vSomeView "  
" WHERE 1=1 "  
" ORDER BY TagName "  
)

device\_results = []  
device\_results = system.db.runQuery(sql\_query, sql\_conn)  
device\_list = [“Devices/%s/LastUpdate” % row[0] for row in device\_results]  
long\_text = ‘\n’.join(device\_list)  
app.util.copy\_to\_clipboard(long\_text)

event.source.parent.getComponent(‘Label Count’).text = “Device Count = %s” % len(device\_list)  
event.source.parent.getComponent(‘Text Area TagChanges’).text = long\_text

to this:

[code]import system  
from app import util  
event.source.running = 0   
sql\_conn = “SQL\_DB\_Name”  
sql\_query = (  
" SELECT TagName "  
" FROM SCADA\_Admin.dbo.vSomeView "  
" WHERE 1=1 "  
" ORDER BY TagName "  
)

device\_results = []  
device\_results = system.db.runQuery(sql\_query, sql\_conn)  
device\_list = [“Devices/%s/LastUpdate” % row[0] for row in device\_results]  
long\_text = ‘\n’.join(device\_list)  
app.util.copy\_to\_clipboard(long\_text)

event.source.parent.getComponent(‘Label Count’).text = “Device Count = %s” % len(device\_list)  
event.source.parent.getComponent(‘Text Area TagChanges’).text = long\_text[/code]

---

<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:** [January 16, 2015, 5:54pm UTC](https://forum.inductiveautomation.com/t/script-errot/9554/4 "2015-01-16T17:54:19Z")

</div>

The missing double quote needs to go at the end of the query string (after the ORDER BY clause).

```auto
ds = system.db.runQuery("Select WorkOrder from workorder WHERE id IN (SELECT workorderid FROM schedule WHERE FinishDateTime >= '%s and FinishDateTime <= '%s') ORDER BY FinishDateTime desc" % (start, end))
```

---

<div class="post-metadata">

**Author:** ![Don\_t\_shoot](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Don\_t\_shoot](https://forum.inductiveautomation.com/u/Don_t_shoot)\
**Post date:** [January 18, 2015, 11:20am UTC](https://forum.inductiveautomation.com/t/script-errot/9554/5 "2015-01-18T11:20:01Z")

</div>

Thanks all the friends helping me, I had put the double quotation marks in the end of the sql query , but it has a new error,as below in the picture.

The workorder do exist , I don’t know where I 'm wrong , and I want to know how to write the sql to realise function what I want in this component .

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f3652e1e2f37ad9cb4a7417b0b86682ed0fc7afd.png)

---

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [January 19, 2015, 4:51pm UTC](https://forum.inductiveautomation.com/t/script-errot/9554/6 "2015-01-19T16:51:02Z")

</div>

Is your workorder table in the ign\_analysis database, because that’s where it seems to be looking for it?

---

<div class="post-metadata">

**Author:** ![Don\_t\_shoot](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Don\_t\_shoot](https://forum.inductiveautomation.com/u/Don_t_shoot)\
**Post date:** [January 20, 2015, 6:58am UTC](https://forum.inductiveautomation.com/t/script-errot/9554/7 "2015-01-20T06:58:32Z")

</div>

Thanks for your help george, In the script binding I want to call on the work order property of work order selector component , and the attachment are the detials of the binding . Thanks for any help again, is there something wrong in my binding ?

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/feee3a8cb145d603d5b757d931d364b2990f82f4.png)  
  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/d/d4f2eed78fbb978a0581764c17b79cef0e851d31.png)

---

<div class="post-metadata">

**Author:** ![george](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/george/32/14066_2.png) [@george](https://forum.inductiveautomation.com/u/george)\
**Post date:** [January 20, 2015, 11:59am UTC](https://forum.inductiveautomation.com/t/script-errot/9554/8 "2015-01-20T11:59:38Z")

</div>

The MySQL error you got earlier is happening on Line 3 of your code, before it even gets to the Line 4 you’ve mentioned. That’s why I asked about the database table name before.
