Script errot

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 !



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?

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]

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

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))

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 .


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

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 ?




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.