Skip to main content
Inspiring
September 6, 2012
Question

cfreturn variable is not recognized when outputing content

  • September 6, 2012
  • 5 replies
  • 1524 views

I have a page that i wish to display total invoices paid to a particular contractor. This Page is Runnign CF9. I'm using a CFC page to write my queries and a action page to display the output via a search box from a search page. Whenever i input the invoice id, coldfusion throws the error: Variable RECENT_INVOICE is undefined"  Am i missing something? my syntax is written below:

<!---CFC PAGE--->

<cfcomponent>

<cffunction name="getinvoice" access="public" returntype="query">

<cfquery name="recent_invoice" datasource="w9">

SELECT invoice.*, project.*, bid.*, CONCAT(w9.w9fname,' ', w9.w9lname,'  ', w9.w9businessname) AS Contractor, w9.*

FROM invoice, project, bid, w9

WHERE invid = #form.invid#

AND INVOICE.invcontractor = W9.w9ID

AND INVOICE.invproject = PROJECT.proID

AND INVOICE.invproject = BID.bidproject

AND INVOICE.invcontractor = BID.bidcontractor

</cfquery>

<cfreturn recent_invoice>

    </cffunction>

</cfcomponent>

<!---Display page that show the invoked query--->

<cfinvoke

  component="invoice.componets.test"

  method="getinvoice"

  returnvariable="recent_invoice">

<!--- CFC Query --->

</cfinvoke>

<!---OUTPUT Items Below--->

<cfoutput>#recent_invoice.invdate# - #recent_invoice.invjob1# - #recent_invoice.invamt1#</cfoutput>

    This topic is closed to new replies. Start a new post to keep the conversation going.

    5 replies

    Miguel-F
    Inspiring
    September 6, 2012

    Looks like you are referencing a form field in your query; form.invid.  You are not submitting a form, you are calling a cfc so you probably want to add an argument to your function and pass the value when you call it.  Change like so:

    <!---CFC PAGE--->

    <cfcomponent>

    <cffunction name="getinvoice" access="public" returntype="query">

    <cfargument name="invid" type="numeric" required="true" />

    <cfquery name="recent_invoice" datasource="w9">

    SELECT invoice.*, project.*, bid.*, CONCAT(w9.w9fname,' ', w9.w9lname,'  ', w9.w9businessname) AS Contractor, w9.*

    FROM invoice, project, bid, w9

    WHERE invid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.invid#" />

    AND INVOICE.invcontractor = W9.w9ID

    AND INVOICE.invproject = PROJECT.proID

    AND INVOICE.invproject = BID.bidproject

    AND INVOICE.invcontractor = BID.bidcontractor

    </cfquery>

    <cfreturn recent_invoice>

    </cffunction>

    </cfcomponent>

    <!---Display page that show the invoked query--->

    <cfinvoke

      component="invoice.componets.test"

      method="getinvoice"

      invid="#yourInvoiceNumber#"

      returnvariable="recent_invoice">

    <!--- CFC Query --->

    </cfinvoke>

    Inspiring
    September 6, 2012

    Thanks for the help. CF is still throwing an error. On the invoke page, I am inserting the invid="#arguments.invid#" as the invid="#yourInvoiceNumber#" could this be the reason that cf is throwing the error?

    Miguel-F
    Inspiring
    September 7, 2012

    Probably.  I meant that as a placeholder for you.  Just replace #yourInvoiceNumber# with the invoice number that you want to query for (like 8 or whatever).  The other variables I gave you, like arguments.invid, do not need to be changed.

    If the invoice number truly is coming from a form field prior to the cfc call then you could change #yourInvoiceNumber# to #form.invid# (or whatever).

    Does that make sense?