Skip navigation
College Kid
Currently Being Moderated

cfreturn variable is not recognized when outputing content

Sep 6, 2012 12:10 PM

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>

 
Replies
  • Currently Being Moderated
    Sep 6, 2012 12:28 PM   in reply to College Kid

    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>

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 6, 2012 5:06 PM   in reply to College Kid

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 10, 2012 5:17 AM   in reply to College Kid

    Sorry I didn't reply sooner. Was off-line all weekend.

     

    Without seeing more of your code I can't pinpoint exactly what the issue is.  One possibilty is that you have not included a condition around your cfinvoke tag so that it only attempts to call your cfc AFTER the form has been submitted.  Something like this:

     

    <cfif IsDefined("form.invid")>

         <!---INVOKE PAGE--->

         <cfinvoke

           component="invoice.componets.test"

           method="getinvoice"

           invid="#form.invid#"

           returnvariable="recent_invoice">

         <!--- CFC Query --->

         </cfinvoke>

    <cfelse>

         <!---FORM PAGE--->

         <form action="2_Try_Test_cfc.cfm" method="get" enctype="application/x-www-form-urlencoded" name="form" id="form">

         <input name="invid" id="invid" type="text" /><input name="submit" type="submit" />

         </form>

    </cfif>

     

     

    That is if the form page is submitting to itself.

    If your form page is submitting to a different page (2_Try_Test_cfc.cfm ?) then your cfc call should be in that page with the reference to your #form.invid# variable.

     

    Remember, you can always use <cfdump var="#form#" /> on pages to see what is available (or not).

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points