CF2018 on Win2016 I wonder if this is a bug. I am ...
# cfml-beginners
e
CF2018 on Win2016 I wonder if this is a bug. I am getting "Element RETURN_ID is undefined in Q1." while running the following:
Copy code
<cfquery name="q1" datasource="#REQUEST.PROD#">
    select return_id 
    from ecomm_returnly_temp
    where return_id NOT IN (select return_id from ecomm_returnly)
    order by return_id        
</cfquery>
Copy code
<cfif #q1.RecordCount# GT "0">
     <cfloop query="q1"> 
        <cfset return_id = #q1.return_id#>
        <cfinclude template="returnly_api_get_return_by_id.cfm">
    </cfloop>
</cfif>
If I convert query data into a list, it works just fine:
Copy code
<cfset returns_list = "">
<cfquery name="q1" datasource="#REQUEST.PROD#">
    select return_id 
    from ecomm_returnly_temp
    where return_id NOT IN (select return_id from ecomm_returnly)
    order by return_id        
</cfquery>
Copy code
<cfset returns_list = ValueList(q1.return_id,",")>

<cfif ListLen(returns_list)>
	<cfloop list="#ListSort(returns_list,"Numeric","asc",",")#" index="return_id">		 
		<cfinclude template="returnly_api_get_return_by_id.cfm">         
	</cfloop>
</cfif>
j
I'd start by taking a look at your conditional <cfif #q1.RecordCount# GT "0"> - no need for the ## around q1.recordcount and no need for the quotes around the zero - just <cfif q1.recordcount gt 0>
e
Thanks, I am always confused when to use/not use # signs. In this case, however, the loop does run, but one time only and then terminates as error pops up.
j
Try a <cfdump var = "#q1#"> before your loop and then in your loop replace your <cfinclude...> with a <cfoutput>#return_id#<br></cfoutput> to see what is being assigned to your return_id variable in both working and not-working version to see what's going on.
e
I've done that already and got back what was expected
a
"Element RETURN_ID is undefined in Q1."
It will also be giving you a line number. Which is fairly critical to solving these sort of things (both for yourself, and when giving other people out of context code)
I don't think this statement serves no purpose in that code you gave is:
Copy code
<cfset return_id = #q1.return_id#>
You already don't need to qualify the column reference with the query name in a query loop. What are you hoping to achieve with that?
And - if your code is actually exactly what you've given us and have not trimmed anything - you don't need the recordCount check either. A query loop will iterate zero times if there are no rows in the query.
And can you please give us a self-contained repro case of what you are seeing. • Swap the cfquery that needs a DB for it to work with just a query object with test data in it. • get rid of the include • show us only the code that is necessary to reproduce the situation You should be doing this already as a matter of course when troubleshooting.
e
Thank you Adam. I've done all of that already and I can see iterating return_id, yet loop terminates after the first return_id. I used recordCount because I am sending myself an email in case of recordCount EQ 0. I use
<cfset return_id = #q1.return_id#>
because <cfinclude ..> comes after that and I use return_id in API call to get return data for single return. At this point I am going to stick with loop over list as it works well. Thanks again.
d
can also just use
Copy code
<cfif q1.RecordCount><cfelse></cfif>
as 0 is false and everything above zero is true
also your variable naming is not great
Copy code
<cfset return_id = #q1.return_id#>
two variables called return_id?? should be something like
Copy code
<cfset this_return_id = #q1.return_id#>
or if template uses return_id, then alias sql with
Copy code
SELECT return_id AS my_return_id
as you might have a collision there with names