Hi Darius, I too went through the same pain (days & days of trying see what data types I could successfully return from a CFC).
I'm still learning but in my somewhat limited experience I could find no way to return an array datatype, it just wouldn't do it no matter what I tried, same goes for structures. I have successfully returned the following datatypes: :String :Query :Boolean :Numeric (yet to try) :Date (yet to try) It's interesting to note that Flex (somehow) in the background actually converts a ColdFusion query to an array. (Search the group on how these can be accessed) At the moment I am mostly using queries to get data back. This has the unfortunate side effect of losing typing (everything in the query is a string), thus you may need cast some results etc to their correct type in Flex. Malcolm -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of coldfs Sent: Friday, 5 August 2005 7:29 AM To: [email protected] Subject: [flexcoders] Calling ArrayStructures in CFCs from Flex Hi, Using Tom Link's blog (http://tomlink.net/blog/index.cfm? mode=entry&entry=B662BEF9-7E97-A3B0-E3FB286E23BDAA50) and other sources, I've been trying for days to translate queries to arrays of structures (and vice versa). Whatever I do, the cfc doesn't except my values from Flex as arrays. I know it's a chunk of code to review, but you'd help a sane man going slowly mad...:-) Many thanks, Darius ----------- index.mxml: ----------- <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"> <mx:Script> <![CDATA[ var RecordSetModel; private function doResult(event:Object):Void{ var method: String = event.call.methodName; if (method == "GetUpdateAuthorization"){ RecordSetModel = event.result; } } private function doClick():Void{ var UserId = "rgatta"; var CountyCode = 37; var CaseFlag = "No"; var CourtOrderAvailableFlag = "No"; var Dsn = "TssDev"; ro.GetUpdateAuthorization (UserId,CountyCode,CaseFlag,CourtOrderAvailableFlag,Dsn); } ]]> </mx:Script> <mx:RemoteObject id="ro" endpoint="http://gx270dev.net/flashservices/gateway" source="Model.mUtilities.mUpdate.qry_UpdateAuthorization" fault="mx.controls.Alert.show(event.fault.faultstring)" showBusyCursor="true"> <mx:method name="GetUpdateAuthorization" result="doResult(event.result)"/> </mx:RemoteObject> <mx:Panel width="100%" title="Forms" height="22%"> <mx:DataGrid id="UpdatesDG" width="166" height="156" wordWrap="true" dataProvider="{RecordSetModel}"> <mx:columns> <mx:Array> <mx:DataGridColumn width="200" headerText="Update Form" columnName="Function"/> <mx:DataGridColumn width="320" headerText="Description" columnName="Description"/> </mx:Array> </mx:columns> </mx:DataGrid> <mx:Button label="Get Records" click="doClick()"/> </mx:Panel> </mx:Application> -------------------------- fx_UpdateAuthorization.cfc -------------------------- <cfcomponent extends="Base"> <cfset obj = createObject ("component","qry_UpdateAuthorization")> <!--- <cffunction name="getEmployees" access="remote" returntype="array"> <cfreturn queryToArrayOfStructures(emp.getEmployees()) > </cffunction> ---> <cffunction name="GetUpdateAuthorization" access="remote" returntype="array"> <cfargument name="AuthorizedUserIdObject" type="array" required="yes"> <cfargument name="CountyCodeObject" type="array" required="yes"> <cfargument name="CaseFlagObject" type="array" required="yes"> <cfargument name="CourtOrderAvailableFlagObject" type="array" required="yes"> <cfargument name="DsnObject" type="array" required="yes"> <cfreturn queryToArrayOfStructures (obj.GetUpdateAuthorization (AuthorizedUserIdObject,CountyCodeObject,CaseFlagObject,CourtOrderAvai lableFlagObject,DsnObject))> </cffunction> </cfcomponent> ----------------------------- qry_UpdateAuthorization.cfc ----------------------------- <cfcomponent extends="Base"> <cffunction name="GetUpdateAuthorization" access="remote" returntype="query"> <cfargument name="AuthorizedUserId" type="array" required="yes"> <cfargument name="CountyCode" type="array" required="yes"> <cfargument name="CaseFlag" type="array" required="yes"> <cfargument name="CourtOrderAvailableFlag" type="array" required="yes"> <cfargument name="Dsn" type="array" required="yes"> <CFSTOREDPROC PROCEDURE="spUpdateAuthorization" DATASOURCE="#Arguments.Dsn#"> <CFPROCPARAM DBVARNAME="AuthorizedUserId" TYPE="IN" VALUE="#Arguments.AuthorizedUserId#" CFSQLTYPE="CF_SQL_CHAR"> <CFPROCPARAM DBVARNAME="CountyCode" TYPE="IN" VALUE="#Arguments.CountyCode#" CFSQLTYPE="CF_SQL_CHAR"> <CFPROCPARAM DBVARNAME="CaseFlag" TYPE="IN" VALUE="#Arguments.CaseFlag#" CFSQLTYPE="CF_SQL_CHAR"> <CFPROCPARAM DBVARNAME="CourtOrderAvailableFlag" TYPE="IN" VALUE="#Arguments.CourtOrderAvailableFlag#" CFSQLTYPE="CF_SQL_CHAR"> <CFPROCRESULT NAME="qGetUpdateAuthorization"> </CFSTOREDPROC> <cfreturn qGetUpdateAuthorization> </cffunction> </cfcomponent> ------------- Base.cfc ------------- <cfcomponent> <cffunction name="dumpToFile" access="package" hint="A quick and easy debugging utility when testing with Flash."> <cfargument name="dumpObject" type="any" required="yes"> <cfargument name="path" type="string" required="yes"> <cfset var varToOutput=""> <cfsavecontent variable="varToOutput"> <cfdump var="#arguments.dumpObject#"> </cfsavecontent> <cffile action="write" file="#arguments.path#" addnewline="yes" output="#varToOutput#"> </cffunction> <cfscript> /** * Converts a query object into an array of structures. * * @param query The query to be transformed * @return This function returns a structure. * @author Nathan Dintenfass ([EMAIL PROTECTED]) * @version 1, September 27, 2001 */ function QueryToArrayOfStructures(theQuery){ var theArray = arraynew(1); var cols = ListtoArray(theQuery.columnlist); var row = 1; var thisRow = ""; var col = 1; for(row = 1; row LTE theQuery.recordcount; row = row + 1){ thisRow = structnew(); for(col = 1; col LTE arraylen(cols); col = col + 1){ thisRow[cols[col]] = theQuery[cols [col]][row]; } arrayAppend(theArray,duplicate(thisRow)); } return(theArray); } /** * Converts an array of structures to a CF Query Object. * 6-19-02: Minor revision by Rob Brooks-Bilson ([EMAIL PROTECTED]) * * Update to handle empty array passed in. Mod by Nathan Dintenfass. Also no longer using list func. * * @param Array The array of structures to be converted to a query object. Assumes each array element contains structure with same (Required) * @return Returns a query object. * @author David Crawford ([EMAIL PROTECTED]) * @version 2, March 19, 2003 */ function arrayOfStructuresToQuery(theArray){ var colNames = ""; var theQuery = queryNew(""); var i=0; var j=0; //if there's nothing in the array, return the empty query if(NOT arrayLen(theArray)) return theQuery; //get the column names into an array = colNames = structKeyArray(theArray[1]); //build the query based on the colNames theQuery = queryNew(arrayToList(colNames)); //add the right number of rows to the query queryAddRow(theQuery, arrayLen(theArray)); //for each element in the array, loop through the columns, populating the query for(i=1; i LTE arrayLen(theArray); i=i+1){ for(j=1; j LTE arrayLen(colNames); j=j+1){ querySetCell(theQuery, colNames[j], theArray[i][colNames[j]], i); } } return theQuery; } </cfscript> </cfcomponent> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links ------------------------ Yahoo! Groups Sponsor --------------------~--> <font face=arial size=-1><a href="http://us.ard.yahoo.com/SIG=12hfr4gsi/M=362329.6886308.7839368.1510227/D=groups/S=1705007207:TM/Y=YAHOO/EXP=1123724868/A=2894321/R=0/SIG=11dvsfulr/*http://youthnoise.com/page.php?page_id=1992 ">Fair play? Video games influencing politics. Click and talk back!</a>.</font> --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

