3 Replies Latest reply on Nov 3, 2006 3:44 PM by Newsgroup_User

    Passing Query to CFC

    Mark Forsberg
      I am passing a query to a cfc. When I dump the query in the cfc it looks fine. However, when I attempt to loop over the query I get the following error: Complex object types cannot be converted to simple values.
      The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.

      Here is the code:

      <cffunction name="updateTYC_Card_Master" access="public" returntype="void">
      <cfargument name="GoodRequests" required="yes" type="query">
      <cfargument name="dsn" required="yes" type="string">
      <cfargument name="newjobNo" required="yes" type="string">

      <!--- <cfdump var="#arguments.goodRequests#">
      <cfabort> --->

      <cfloop query="#ARGUMENTS.GoodRequests#">
      <cfquery name="UpdateTYC_Card_Master" datasource="#ARGUMENTS.dsn#">
      Update READONLY.TYC_Card_Master
      Set Job_Key = #ARGUMENTS.jobNo#
      Where custno = #custno#
      And job_key = -1

      How would I go about being able to use the contents of the query that I passed into the cfc. I've never passed in a query before. Thanks for the help.

        • 1. Passing Query to CFC
          Dan Bracuk Level 5
          It has nothing to do with your query. This
          <cfargument name="newjobNo" required="yes" type="string">

          does not match this
          Set Job_Key = #ARGUMENTS.jobNo#

          Also, your argument specifies a string but your sql does not have quotes.

          Finally, since you are setting all the records to the same new job number, instead of running a query inside a loop, it is probably more efficient to run one query which includes something like

          where custno in (#ValueList(arguments.yourquery.custno)#)
          • 2. Re: Passing Query to CFC
            Mark Forsberg Level 1

            Thanks for the assist. I was so wrapped up in the passing of the query that I overlooked the obvious. I'll give it a go using the valueList.
            Again, thanks for the help.

            • 3. Re: Passing Query to CFC
              Level 7
              > It has nothing to do with your query. This

              Well it kind of does.

              > <cfloop query="#ARGUMENTS.GoodRequests#">

              The query parameter takes the NAME of the query, not the *actual query*.

              Lose the pound-signs.