Scripting to a label in Perspective

I’ve tried this multiple ways and I’m getting close but I fail every time. We have multiple lines that operate on a daily basis and I’m reading values from a SQL table to tell me if the line is active or not and I am trying to create a dashboard that will show a performance value if they’re active otherwise it will show them as not being active. This works in the script console:

l=‘010B LH’
x=system.db.runPrepQuery(“select convert(varchar(50),FORMAT(perf,‘p’)) from assy_prodlog where line = ? AND evntstart < getdate() AND evntend > getdate()”,[l])
b = 'Performance is: ’
if x.getRowCount() > 0:
print b + x.getValueAt(0,0)
else:
print “This line is currently not active!”

Putting this in the script console works like a charm. But I’m not sure how to set this as the script on a label in perspective. I can run the SQL query from a name query but it’s also passing through a column heading with multiple quotation marks and brackets. Has anyone experienced this?

You would want to save that query as a Named Query. If you set the query type to Scalar you can get just the value.

Bind the label against the Named Query.

You can handle the conditional logic which checks the returned value count in a transform, OR you could set a fallback value in the Named Query in the result no match is found.

1 Like

That works. I knew it was easy, I just wasn’t getting it! Thank you friend!

1 Like