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