RunQuery in Script Editor

Hi, I want to make a EventHandler when the check box is selected.
I want to change the property of the data range (start/end date) with the SQL Query .
I only have to select the date from the table HISTORICOS_OF where OF = intValue of a Component (Numeric Text Box) and change the dates of the data range.

The Code:

The Error…

Any help?

A query returns a dataset. If you need it to return the single value, try using system.db.runScalarQuery()

1 Like

As @JordanCClark says, if you want a query to return a single value use the scalar Query function, however, I would recommend that you combine the two queries and then get the data from that. Assuming that the columns in the table are the correct data type that would look something like this.

OF = event.source.parent.getComponent('Busca_OF').intValue
dsDates = system.db.runPrepQuery('SELECT FECHAINICIO, FECHAFIN FROM HISTORICOS_OF WHERE ORDEN = ?',[OF],'again')
if event.source.selected:
    event.source.parent.parent.getComponent('Date Range').startDate = dsDates.getValueAt(0,0)
    event.source.parent.parent.getComponent('Date Range').endDate = dsDates.getValueAt(0,1)

Thanks Jordan! It worked!
I only have one more question…
What can i do if OF is not finded in SQL Server?
I want if I get any error message related with that, to stop the pop up message and show something like ‘OF not found’

The value returned would be None, if I recall correctly.