Expand my Community achievements bar.

How to throw a custom error if ODBC query returns no records?

Avatar

Former Community Member

Hi,

My form allows the user to imput criteria in a search box and then click a SEARCH button or press ENTER to return a matching result of a record from an ODBC connected database.  There should only be one unique match to return as the user is entering an ID number.

I am stuck on providing a nice error message if the search returns no records e.g. if the user search an invalid ID number.  Currently the user is getting the ugly XFA error:  

Script Failed (language is formcal; contxt is xfa[0].form[0]topmostSubform[0].Page1[0].Button1[0]) script=...   Error: first operation failed there are no records in the datasource.

I don't know how to catch the null recordset without an XFA error and instead throw my own custom messagebox at the user.  I am suck on catching the error or EOF and using it as a trigger to run a custom message box.

In my research I believe the solution might involve using EOF Action settings.  Unfortunatly I haven't been able to find much documentation or practical examples of it's ugage.  Whenever I've tried to expiriment I've only ended up with broken code/script.  I have no idea to work with EOF's.

Here is my current formcalc script when the user clicks the search button:

//Define SQL to run

var oDC = Ref($sourceSet.EstabSearchResults.clone(1))     //Cloning of the SourceSet due to using XFA Specification 2.5 or higher. 

oDC.#command.query.commandType = "text"

oDC.#command.query.select = concat("SELECT ESTAB_NAME, OWNER_NAME, ESTAB_ADDRESS, ESTAB_CITY, [...more SQL query criteria....] FROM ESTABLISHMENT WHERE (GAZ_NUMBER LIKE '",EstabSearchField.rawValue,"');")

//Do the new connection

oDC.open()

oDC.first()

How do I catch an EOF or null recordset when oDC.first() is run?

Also, sorry I don't really have good examples of what I've tried.  My attempts were laughable.  Any ideas or suggestions on how to work with this scenario would be greatly appreciated.

Thanks!

-Mike


0 Replies