ColdFusion Developers - Spot the Mistake

Take a look at this code:

<cffunction name="getFilterString" output="false" access="public" returntype="string" hint="I return the search filter list">
<cfargument name="avoid" type="string" default="" />
<cfset var x = "" />
<cfset var dynHasFunct = "" />
<cfset var dynGetFunc = "" />
<cfset var rtnVal = "" />

<cfloop collection="#variables.instance#" item="x">
<cfset dynHasFunc = variables["has#x#"] />
<cfset dynGetFunc = variables["get#x#"] />
<cfif NOT listFind( arguments.avoid, x) AND dynHasFunc() >
<cfset listAppend( rtnVal, "#x#=#dynGetFunc()#", "&") />
</cfif>
</cfloop>
<cfreturn rtnVal />
</cffunction>

I just spent 15 minutes tracing all this code out trying to find out why nothing was returned. The intent of the code is to build a string containing values present in the object. So if a user searches by Category, UserID etc, the search string is maintained.

Warning, the error is simpler than you might think. Don't over think it.

Comments
<cfset listAppend( rtnVal, "#x#=#dynGetFunc()#", "&") /> shouldn't it be
<cfset rtnval = listAppend( rtnVal, "#x#=#dynGetFunc()#", "&") /> ?
# Posted By João Fernandes | 9/11/07 8:43 PM
My guess is:

<cfset listAppend( rtnVal, "#x#=#dynGetFunc()#", "&") />

Should be:
<cfset rtnVal = listAppend( rtnVal, "#x#=#dynGetFunc()#", "&") />

Some functions in CF "do" something to a value (eg: arrayAppend, queryAddRow), and others return the value (eg: listAppend)
# Posted By David | 9/11/07 8:44 PM
ListAppend() returns the appended list unlike ArrayAppend which returns just success or failure.

So you need to set rtnVal = listAppend()....
# Posted By Terrence Ryan | 9/11/07 8:44 PM
@All,

All of you are correct and yeah, it has been that kind of a day.

Here's to checking the simplest things first,

DW
# Posted By Dan Wilson | 9/11/07 10:02 PM
I can't speak for the others, but the only reason I spotted it so quickly is case I've been down that road many times before!
# Posted By David | 9/11/07 10:18 PM
Done that at least 10 times.
# Posted By Mitch | 9/12/07 2:14 AM
Maybe its because I haven't had enough caffeine this morning, but where is variables.instance defined?
# Posted By Jason | 9/12/07 9:20 AM
Looks to be a function within a component, variables.instance is most likely declared in the contructor code of the component.
# Posted By Quan | 9/12/07 10:23 AM
variables.instance would be defined in the init method.
# Posted By Justin | 9/12/07 10:25 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.001. Contact Blog Owner