Complex object types cannot be converted to simple values?
Copy link to clipboard
Copied
Hello,
I am a newbie to coldfusion attempting to list the contents of a directory and keep getting an error that reads Complex object types cannot be converted to simple values. The error is occurring on line 11, at .<cfloop collection="#picturelist#. Any help would be greatly appreciated!
<cfset basefolder = "\\url\Corner_Reports" >
<cfdirectory recurse="no" action="list" directory="#basefolder#" filter="*.pdf" name="picturelist">
<cfdump var="#picturelist#">
<cfloop collection="#picturelist# " item="thefile">
<cfset filetoread = "#picturelist.directory#\#picturelist.name#">
<cfoutput query ="corner_reports">
Looking in: #filetoread# --
<cffile action="read" file="#filetoread#" variable="filetext">
<a href="#picturelist.Directory#\#picturelist.name#index.htm" title="#picturelist.name#">
</cfoutput>
</cfloop>
Copy link to clipboard
Copied
Collection loops work on structs, not recordsets. Use a query loop.
Here're the relevant docs for your perusal (always a good first port of call when something ain't working):
CFLOOP
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fe2.html
--
Adam
Copy link to clipboard
Copied
Thanks for the advice.
I changed my loop to a query loop and am still getting the same message about complex object types. Is there something else I am missing?
<cfset basefolder = "
url\g$\Images\CORNER_REPORTS\0" >
</cfloop
Copy link to clipboard
Copied
Hi
If you want to post code, you need to do it via the web UI (http://forums.adobe.com/message/3770618#3770618). Posting code via email dun't work.
But you should be able to work this out for yourself. The error will be giving you a line number, and on that line you're trying to do something like:
<cfoutput>#aRecordSet#</cfoutput>
There are certain operations in CF that can only be performed on simple values, whereas you're trying to do this on a complex value (record set, struct, array, etc).
Also: if you have an error on the screen, don't DESCRIBE the error, eg: "getting the same message about complex object types". Post the *actual error*. I strongly doubt it's exactly the same error (same line, same code); it's just a similar one.
Post your code again via the web UI, and we'll sort it out.
--
Adam
Copy link to clipboard
Copied
Thanks again Adam. I know my code is far from working, I just need a shove in the right direction. With the following code I get an error on line 17 <cfloop query="#picturelist#"> saying that complex object types cannot be converted to simple values.
<cfquery name="corner_reports" datasource="sire" dbtype="odbc">
select*
from sire.dbo.CORNER_REPORTS_Page
</cfquery>
<cfset basefolder = "\\url\g$\Images\CORNER_REPORTS\0" >
<cfdirectory recurse="no" action="list" directory="#basefolder#" filter="*.jpg" name="picturelist">
<cfdump var="#picturelist#">
<cfloop query="#picturelist#">
<cfset filetoread = "#picturelist.directory#\#picturelist.name#">
<cfoutput query ="corner_reports">
Looking in: #filetoread#
<cffile action="read" file="#basefolder#" variable="filetext">
<a href="#picturelist.Directory#\#picturelist.name#index.htm" title="#picturelist.name#">
</cfoutput>
</cfloop>
Copy link to clipboard
Copied
<cfloop query="#picturelist#"> should be <cfloop query="picturelist">
Copy link to clipboard
Copied
Good spot.
It's a bit of an odd one this. For some reason CFOUTPUT and CFLOOP query loops take the NAME of a recordset variable, not the value of it.
Everyone's fallen foul of this at some stage or other.
--
Adam

