• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfreturn variable is not recognized when outputing content

Explorer ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

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>

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 07, 2012 Sep 07, 2012

Copy link to clipboard

Copied

Yes sir. I may be doing something with the text box not being defined. The following error is being thrown:  Element INVID is undefined in FORM. i do know thw in my form page the text box is named invid:

<!---CFC PAGE--->

<cfcomponent>

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

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

<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>

<!---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>

<!---INVOKE PAGE--->

<cfinvoke

  component="invoice.componets.test" 

  method="getinvoice"

  invid="#form.invid#"

  returnvariable="recent_invoice">

<!--- CFC Query --->

</cfinvoke>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

LATEST

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation