Written by

Question Nezla · 1 hr ago

Unrecognized class in a Production Business Operation call

Hi Guys,

I've this Business operation pointing to my DSN as below 

where its calling the this method, but for some reason its not recognizing Ens.Util.LookupTable class   

 

I can query the class from SMP with no issues, and also the Business Operation works fine if I use table from my Synergy DSN but not sure why is not recognizing Ens.Util.LookupTable system table do I need to include or initialise something ? 

Thanks

Product version: IRIS 2025.3

Comments

Yaron Munz · 1 hr ago

The lookup read code seems ok. the error suggests that the table Ens.Util.LookupTable doesn't exist in SQL DB.
Are you sure that table you can successfully call from the portal is not local in IRIS?

0
Julian Matthews · 1 hr ago

Hey Nezla, if you are looking to interact with an internal table, then using the outbound adapter for SQL is not what will work for you. This is because the adapter relies on the servers ODBC config to look for the specified table in the external database based on the DSN you've configured. 

You will instead want to swap your ObjectScript to something like:

Set tStatement = ##class(%SQL.Statement).%New()
Set tQuery = "SELECT * From Ens_Util.LookupTable WHERE TableName ='"_tTable_"'"
$$$THROWONERROR(tSC,tStatement.%Prepare(tQuery))

Set tResult = tStatement.%Execute()

While tResult.%Next(){

	//Do what you need to with the results here

	$$$TRACE("Result: "_tResult.KeyName_", "_tResult.KeyValue)

}

Then, if you still need to also query for something in the external database based on the DSN configured, then you can interact with the external database using the ..Adapter.ExecuteQuery approach you had attempted.

0
Julian Matthews  1 hr ago to Julian Matthews

Additionally, it's best that you avoid concatenation for building the string of your query, and should instead use parameters to avoid issues with unexpected characters breaking your query (or, in some scenarios, opening yourself up to exploits via SQL injection).

My example above should instead be:

Set tStatement = ##class(%SQL.Statement).%New()
Set tQuery = "SELECT * From Ens_Util.LookupTable WHERE TableName = ?"
$$$THROWONERROR(tSC,tStatement.%Prepare(tQuery))

Set tResult = tStatement.%Execute(tTable)

While tResult.%Next(){
	//Do what you need to with the results here
	$$$TRACE("Result: "_tResult.KeyName_", "_tResult.KeyValue)

}

Note that the table name is a ? in the initial query string, and the value of the table name is being referenced in the %Execute() method

0