Skip to main content
May 2, 2006
Answered

CFC troubles

In the code below I get a "viewall undefined" error. before sending it to the cfc ,if it is not defined, I set it, so it should always have a value. Am I using the cfinvokeargument wrong? Do I have to put all variables into an array? I have other cfc's that work when only sending 1 variable, as soon as I try to send more I get the undefined errors.

.cfm

<cfif not isdefined('viewall')><cfset viewall = 1></cfif>
<cfif not isdefined('asc')><cfset asc=1></cfif>
<cfif not isdefined('to')><cfset to = #createodbcdatetime('1-1-3000')#></cfif>
<cfif not isdefined('from')><cfset from = #createodbcdatetime('1-1-1901')#></cfif>

<cfinvoke component="query" method="query_total_all_exp" returnvariable="total">
<cfinvokeargument name="viewall" value="#viewall#">
<cfinvokeargument name="team" value="#team#">
<cfinvokeargument name="asc" value="#asc#">
<cfinvokeargument name="to" value="#to#">
<cfinvokeargument name="from" value="#from#">
<cfif isdefined('account')><cfinvokeargument name="account" value="#account#"></cfif>
<cfif isdefined('workorder')><cfinvokeargument name="workorder" value="#workorder#"></cfif>
</cfinvoke>


.cfc
<cfcomponent>
<cffunction name="query_total_all_exp" access="public">
<cfif viewall eq 1> <!--- at this point I get a viewall undefined error --->
<cfif asc eq 1>
<cfif isdefined('account')>
<cfquery name = "total" dataSource="KFS">
SELECT *
FROM tbl_expenditures
WHERE team='#team#' and account = '#account#' and cast(CONVERT(char(10),PDate,101) as datetime) BETWEEN '#dateFormat(from, "mm/dd/yyyy")#' AND '#dateFormat(to, "mm/dd/yyyy")#'
ORDER BY pdate asc
</cfquery>
<cfelseif isdefined('workorder')>
<cfquery name = "total" dataSource="KFS">
SELECT ID, CAST(LineItem AS numeric) as 'LineItem',
case PDate when '1/1/1900' then NULL else cast(CONVERT(char(10),PDate,101) as datetime) end as 'PDate',
case SDate when '1/1/1900' then NULL else cast(CONVERT(char(10),SDate,101) as datetime) end as 'SDate',Method,Team,Vendor,Description, Amount, Account,Cleared,WorkOrder,Notes,Estimate
FROM tbl_expenditures
WHERE team='#team#' and cleared = 1 and workorder = '#workorder#' and cast(CONVERT(char(10),PDate,101) as datetime) BETWEEN '#dateFormat(from, "mm/dd/yyyy")#' AND '#dateFormat(to, "mm/dd/yyyy")#'
ORDER BY pdate asc
</cfquery>
</cfif>
<cfelse><!--- This goes on an on but I will end it here for disscussion --->
</cfif>
</cfif>
<cfreturn total>
</cffunction>
</cfcomponent>
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer
May 2, 2006
When passing in multiple arguments you need to use cfargument in your cfc like this

<cffunction name="query_total_all_exp" access="public">
<cfargument name="viewall" type="nemeric" required="yes" />
<cfargument name="team" type="string" required="yes" />

etc.

3 replies

May 3, 2006
Thanks! All is well and good now!
Translate
Correct answer
May 2, 2006
When passing in multiple arguments you need to use cfargument in your cfc like this

<cffunction name="query_total_all_exp" access="public">
<cfargument name="viewall" type="nemeric" required="yes" />
<cfargument name="team" type="string" required="yes" />

etc.
Translate
Inspiring
May 2, 2006
This is a reply to "Do I have to put all variables into an array?"

No, but you could put them into a structure. In fact that's how I pass arguments to functions. Let's say a function named abc needs two arguments, x and y. Also assume that we have already created our object, and the variable is called MyObject.

args = StructNew();
args.x = "something";
args.y = "something else";
somevariable = MyObject.abc(argumentcollection = args);


Translate