1

I am getting Variable undefined error when i try to invoke a function from a cfc. The best part is it is already defined above. "IandI" is the cfc name.

Code snippet :

<cfparam name="TotalCorpAudits" default="0">
<cfset TotalAudits = TotalSiteAudits + TotalCorpAudits>
<cfinvoke   component="#IandI#"
  method="calcRate" 
  Cases="#TotalCorpAudits#"
  Hours="#TotalAudits#"
  iiFactor="1"
  convertToPercent="true"
  NumberFormatOn="true"
  returnOnZeroHours="0"
  returnOnNonNumericData="0"
  returnvariable="TotalCorpRatioAudits"
>

Getting error at ... Cases="#TotalCorpAudits#"

CFC Code :

<cffunction name="calcRate" access="public" returntype="string"
  displayname="calcs Rate" hint="" description="">              
  <cfargument name="Hours" required="Yes" type="string">
  <cfargument name="Cases" required="Yes" type="string">
  <cfargument name="IIFactor" required="No" type="numeric" default="200000">
  <cfargument name="FormatMask" required="No" type="string" default="999.99">
  <cfargument name="NumberFormatOn" required="No" type="boolean" default="false">
  <cfargument name="returnOnZeroHours" required="No" type="string" default="0">
  <cfargument name="returnOnNonNumericData" required="No" type="string" default="N/A">
  <cfargument name="returnOnZeroCasesWithHours" required="No" type="string" default="0">
  <cfargument name="convertToPercent" required="No" type="boolean" default="false"> 
Matt Busche
  • 14,216
  • 5
  • 36
  • 61
Vasu
  • 319
  • 5
  • 19
  • See i have already defined the "TotalCorpAudits" using cfparam. But still getting error at line...... Cases="#TotalCorpAudits#" – Vasu Mar 26 '14 at 11:25
  • 1
    can you include the stacktrace? If it's getting past the `cfset` you shouldn't have an error where you have it – Matt Busche Mar 26 '14 at 12:00
  • 2
    The problem is more likely with the variable in your component attribute. Hard code a value and see what happens. – Dan Bracuk Mar 26 '14 at 12:14

3 Answers3

1

CFINVOKE works like so:

<cfinvoke component="[CFC_FileName]" method="calcRate" returnvariable="TotalCorpRatioAudits">
    <cfinvokeargument name="Hours" value="[whateverValueYouWant]">
    <cfinvokeargument name="Cases" value="[whateverValueYouWant]">
</cfinvoke>

Notice a couple things: <cfinvokeargument> is underneath the <cfinvoke> tag. Also, I only used those two argument since they were required in the CFC, but you can add more if needed. Use https://wikidocs.adobe.com/wiki/display/coldfusionen/cfinvoke as a reference.

Chester
  • 1,081
  • 9
  • 18
0

is the name of component comeing from a variables? Is IandI a variable? If it is not you dont have to wrap it in # signs. And that is what I think is causing the problem.

CFML_Developer
  • 1,565
  • 7
  • 18
0

I've run into this a few times lately; it definitely seems like a bug in the ColdFusion engine. Seems as if the compiler is trying to evaluate the variable from within the CFC, rather than the calling page. I've been able to work around it by defining my struct of arguments beforehand, then simply including the struct in the invoke().

<cfset argStruct = {argName1=val1,argName2=val2,argName3="hardcodedValue"}>
<cfinvoke component="cfcPath" method="methodName" argumentCollection="#argStruct#" />
mykaf
  • 1,034
  • 1
  • 9
  • 12