Query cfscript

I have a cfc that works fine in tag mode.

<cfcomponent output="false">

<cffunction name=GetCases access="remote" returntype=Any returnformat=JSON>
  <cfquery name="QryCases" datasource=#session.dsn# >
   select id,surname,forename,died,dob,status from tbcases
    </cfquery>
  <cfreturn (QryCases)>
</cffunction>

</cfcomponent>

but the cfscript version fails and I just cant see why.

component
{

	function any GetCases() access="remote" returntype="any"  returnformat="json"
	{
	
		QryCases = Queryexecute("
			select id,surname,forename,died,dob,status from tbcases
				","",{datasource=session.dsn});
	
		return QryCases;
	}
	
}

Do you get any error message at all?

My initial thought is the second parameter for queryExecute, I thought it could only be either an array or structure, not a string?

no error! Both tag based and script based return the same type. JSON. makes no sense at all…

ps both work in ACF, only the tag on works Lucee.

Does this work?

remote any function GetCases() returnFormat="json"{
{
	QryCases = Queryexecute("
		select id,surname,forename,died,dob,status from tbcases
			",{},{datasource=session.dsn});
	return QryCases;
}

YES!
It does!
so the 2nd parameter was the issue and thanks to both of you…
Also FYI it will also work if the return type and access are in the original place…

Very hard to debug these things, logs show no issue…

thanks

I’d recommend using Dump() to check what the function is actually returning, rather than logs. When I did that Lucee (5.2.3) flagged up the parameter issue and problems with the function syntax.

1 Like

thankyou.