CFQuery where param - sql

In my CF component, I tried to filter data from user input (getSearchString) and run the code, I having problem with WHERE function. Can suggestion what is the correct way?
<cffunction name="getParks" access="remote" returntype="struct">
<cfargument name="page" required="true" />
<cfargument name="pageSize" required="true" />
<cfargument name="gridsortcolumn" required="true" />
<cfargument name="gridsortdirection" required="true" />
<cfargument name="getSearchString" default="" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "parkName" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="parks" datasource="cfdocexamples">
select parkName, parkType, city, state
from parks
where <cfqueryPARAM value = "#getSearchString#" CFSQLType = "CF_SQL_VARCHAR">
order by #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn queryconvertforgrid(parks, page, pagesize) />

It seems to be a simple sql bug. The field which you would like to compare with your searchstring is missing.
Should rather be:
<cfquery name="parks" datasource="cfdocexamples">
select parkName, parkType, city, state
from parks
where parkName = <cfqueryPARAM value = "#getSearchString#" CFSQLType = "CF_SQL_VARCHAR">
order by #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>

acctually not around param but around getSearchString:
WHERE parkName LIKE ... "%#getSearchString#%" ... But beware of performance issue with LIKE, also if you have large number of entries, dataGrid doesn't do real paging. Full blown solution depends on your database type.

Related

I am trying to create basic datatables.net and coldfusion server side example but it doesnt seem to works

This example was based on this link
https://datatables.net/forums/discussion/40613/datatable-jquery-server-side-with-adobe-cold-fusion-and-sql-server
and i am using datatable version 1.10
On first page load, all data sucessfully loaded into #formsTable
But it wont work when clicking sorting,searching and paging.
It just hang with 'processing..'
pageA.cfm (only show scripting part here...)
<script type="text/javascript">
$(document).ready(function(){
$('#formsTable').DataTable({
processing:true,
serverSide:true,
ajax:{
url:'pageB.cfm'
},
columns:[
{title: "id",data:'id'},
{title: "Name",data:'name'},
{title: "Emp.No",data:'empno'},
{title: "IC",data:'ic'}
]
})
})
</script>
pageB.cfm (server-side)
<cfcontent reset="true">
<cfset listColumns = "id,emp_no,emp_name,number_id2" />
<cfset sIndexColumn = "id" />
<cfparam name="draw" default="1" type="integer" />
<cfparam name="start" default="0" type="integer" />
<cfparam name="length" default="10" type="integer" />
<cfparam name="url.sSearch" default="" type="string" />
<cfparam name="url.iSortingCols" default="0" type="integer" />
<!--- query data --->
<cfquery datasource="hrms" name="qFiltered">
select id,emp_no,emp_name,number_id2 from employee
<cfif len(trim(url.sSearch))>
Where
(
<cfloop list="#listColumns#" index="thisColumn">
<cfif thisColumn neq listFirst(listColumns)>
OR
</cfif>
#thisColumn# LIKE <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#trim(url.sSearch)#%" />
</cfloop>
)
</cfif>
<cfif url.iSortingCols gt 0>
ORDER BY
<cfloop from="0" to="#url.iSortingCols-1#" index="thisS">
<cfif thisS is not 0>, </cfif>
#listGetAt(listColumns,(url["iSortCol_"&thisS]+1))#
<cfif listFindNoCase("asc,desc",url["sSortDir_"&thisS]) gt 0>
#url["sSortDir_"&thisS]#
</cfif>
</cfloop>
</cfif>
</cfquery>
<!--- query data count --->
<cfquery dbtype="query" name="qCount">
SELECT COUNT(#sIndexColumn#) as total
FROM qFiltered
</cfquery>
<!--- Output --->
{"draw": <cfoutput>#val(draw)#</cfoutput>,
"recordsTotal": <cfoutput>#qCount.total#</cfoutput>,
"recordsFiltered": <cfoutput>#qFiltered.recordCount#</cfoutput>,
"aaData": [
<cfoutput query="qFiltered" startrow="#val(start+1)#" maxrows="#val(length)#">
<cfif currentRow gt (start+1)>,</cfif>
{
"id":#SerializeJSON(qFiltered.currentrow)#,
"name":#SerializeJSON(qFiltered.emp_name)#,
"empno":#SerializeJSON(qFiltered.emp_no)#,
"ic":
<cfif trim(qFiltered.number_id2) neq '[empty string]'>
#SerializeJSON(qFiltered.number_id2)#
<cfelse>
""
</cfif>
}
</cfoutput> ] }
I am stuck here , it seems that something is missing on pageB.cfm ?
Edited:
thanks for #user12031119 pointing out that sent parameter from pageA.cfm to pageB.cfm is different now with v1.10, so basically these parameters should be change :-
sEcho : draw
iDisplayStart : start
iDisplayLength : length
iTotalRecords : recordsTotal
iTotalDisplayRecords : recordsFiltered
with that change i can now click on next/prev page (paging) but still search and sorting dont work
Yes, unfortunately the code sample you're viewing on datatables.net is for legacy datatables. Under datatables 1.10.x, you will have to use the upgraded keys which version 1.10 expects in your returned json structure. It looks like you already updated pageA.cfm with the new parameters, however you also need to update your server-side return parameters in pageB.cfm.
Here's a guide to upgrade to version 1.10 https://datatables.net/upgrade/1.10
Here's a guide for the new parameters for server-side 1.10 https://datatables.net/manual/server-side
Edit 1 thanks to James A Mohler
Edit 2 per issue noticed by myself
Apparently I was mistaken that datatables only accepts an array of arrays when returned from the server. Apparently it also accepts an array of structs, which helps simplify my answer. However, this will require aliasing the columns in the select statement to match the column definitions defined in pageA.cfm. With that said, here are the changes needed.
The first code modification to pageB.cfm will be to alias the columns in your select statemen to match their definition in pageA.cfm.
<cfquery datasource="hrms" name="qFiltered">
select id as id, emp_no as empno, emp_name as name, number_id2 as ic from employee
Once that's done, change the following in your <cfoutput> block from pageB.cfm
Change sEcho to draw
Change iTotalRecords to recordsTotal
Change iTotalDisplayRecords to recordsFiltered
Change aaData to data
Use serializeJson() with the "struct" option to return an array of structs with the key values matching up to how you defined them in pageA.cfm. If you're using ACF instead of lucee, then you might have to change your column definitions in pageA.cfm to uppercase since ACF doesn't preserve case and uppercases key names.
<!--- Output --->
<cfoutput>
{
"draw": #val(url.sEcho)#,
"recordsTotal": #qCount.total#,
"recordsFiltered": #qFiltered.recordCount#,
"data": #serializeJson(qFiltered, "struct")#
}
</cfoutput>
First, check that your JSON output is valid (jsonlint.com)
Then, wrap your JSON output into a cfsavecontent:
<cfsavecontent variable="json">
<cfoutput>
your output here
</cfoutput>
</cfsavecontent>
Then use this code to return the JSON:
<cfset lastModDate = DateFormat(Now(),'ddd, dd mmm YYYY') & ' ' & TimeFormat(DateConvert('local2Utc', Now()), 'HH:mm:ss') & ' GMT'>
<cfheader name="Expires" value="#DateAdd('m', -1, Now())#">
<cfheader name="Last-Modified" value="#lastModDate#">
<cfheader name="cache-control" value="must-revalidate">
<cfheader name="Pragma" value="no-cache">
<cfcontent type="text/x-json" />
<cfoutput>#json#</cfoutput>
OK finally it works now.
So this is it, basic datatables.net coldfusion/lucee server side example.
Datatables Version 1.10.xx
Language Coldfusion/lucee
pageA.cfm (scripting)
<script type="text/javascript">
$(document).ready(function(){
$('#formsTable').DataTable({
processing:true,
serverSide:true,
ajax:{
url:'pageB.cfm',
type :'post'
},
columns:[
{title: "id",data:'id'},
{title: "Name",data:'name'},
{title: "Emp.No",data:'empno'},
{title: "IC",data:'ic'}
],
language: {
infoEmpty: "No records available",
}
})
})
</script>
pageB.cfm
<cfcontent reset="true">
<cfset listColumns = "id,emp_no,emp_name,number_id2" />
<cfset sIndexColumn = "id" />
<cfparam name="draw" default="1" type="integer" />
<cfparam name="start" default="0" type="integer" />
<cfparam name="length" default="10" type="integer" />
<cfparam name="search" default="" type="string" />
<cfif len(form["search[value]"]) gt 0>
<cfset search=form["search[value]"]>
</cfif>
<!--- Data set after filtering --->
<cfquery datasource="hrms" name="qFiltered">
select id,emp_no,emp_name,number_id2 from employee
<cfif len(trim(search))>
where
(
<cfloop list="#listColumns#" index="thisColumn">
<cfif thisColumn neq listFirst(listColumns)>
OR
</cfif>
#thisColumn# LIKE <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="%#trim(search)#%" />
</cfloop>
)
</cfif>
<cfif form["order[0][column]"] gt 0>
ORDER BY
<cfif form["order[0][column]"] eq '1'>
emp_name <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '2'>
emp_no <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '3'>
number_id2 <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
</cfif>
</cfquery>
<!--- Total data set length --->
<cfquery dbtype="query" name="qCount">
SELECT COUNT(#sIndexColumn#) as total
FROM qFiltered
</cfquery>
<cfif qFiltered.recordcount gt 0>
<cfset recordsTotal=#qCount.total#>
<cfelse>
<cfset recordsTotal=0>
</cfif>
<!---
Output
--->
{"draw": <cfoutput>#val(draw)#</cfoutput>,
"recordsTotal": <cfoutput>#recordsTotal#</cfoutput>,
"recordsFiltered": <cfoutput>#qFiltered.recordCount#</cfoutput>,
"data":
<cfif qFiltered.recordcount gt 0>
[
<cfoutput query="qFiltered" startrow="#val(start+1)#" maxrows="#val(length)#">
<cfif currentRow gt (start+1)>,</cfif>
{
"id":#SerializeJSON(qFiltered.currentrow)#,
"name":#SerializeJSON(qFiltered.emp_name)#,
"empno":#SerializeJSON(qFiltered.emp_no)#,
"ic":
<cfif trim(qFiltered.number_id2) neq '[empty string]'>
#SerializeJSON(qFiltered.number_id2)#
<cfelse>
""
</cfif>
}
</cfoutput> ]
<cfelse>
""
</cfif>
}

ColdFusion 2018 Bean-DAO-Manager OOP Logic Errors

I am trying to learn about OOP in ColdFusion by recreating a proven Bean-DAO-Manager setup. In the example, I only use Create but the issue also exists for Read, Update and Delete.
I think I make some mistakes when passing the arguments.
From index.cfc, I create an object from testBeanDaoManager.cfc, which holds the API. Here, the bean is created that should hold the properties. From there the manager is called which calls the db-query in the file testDAO.cfc.
The error states that the bean's method getName() was not found (more details at the end of the post).
Any help is greatly appreciated.
Database and table: testBeanDao.APP.TESTBEAN
Files:
/index.cfm, /api/testBeanDaoManager.cfc, /logic/bean/testBean.cfc, /logic/dao/testDAO.cfc, /logic/manager/testManager.cfc
/index.cfm:
<cfscript>
obj = createObject("component","api.testBeanDaoManager");
add = invoke(obj,"addName", {ID=0, Name="Meo"});
</cfscript>
/api/testBeanDaoManager.cfc
component rest=true restpath="names" {
remote any function gettestBean(ID){
var nameManager = createObject('component', 'logic.manager.testManager');
var nameBean = nameManager.getName(arguments.ID);
return nameBean;
}
remote any function addName(numeric ID, string Name, restArgSource="path", any Data = {}) httpmethod="post" restpath="add/{id}" {
var bean = gettestBean(arguments.ID);
var nameManager = createObject('component', 'logic.manager.testManager');
bean.setName(arguments.Name);
bean = nameManager.addName(bean);
return bean;
}
}
/logic/manager/testManager.cfc
<cfcomponent output="false" >
<cffunction name="init" output="false" access="public" returntype="testManager">
<cfset super.init( gateway=createObject("component","logic.gateway.testGateway").init(), DAO=createObject("component","logic.dao.testDAO").init())
/>
<cfreturn this />
</cffunction>
/**
* Initializing Bean
*/
<cffunction name="gettestBean" output="false" returntype="any">
<cfset var bean = createObject("component","logic.bean.testBean") />
<cfreturn bean />
</cffunction>
<cffunction name="addName" output="false" returntype="any">
<cfargument name="bean" required="true" />
<cfset var dao = createObject("component","logic.dao.testDAO") />
<cfset dao.insertName(bean) />
<cfreturn bean />
</cffunction>
...
/logic/dao/testDAO.cfc
<cffunction name="insertName" returntype="any" output="false">
<cfargument name="bean" type="any" required="true" />
<cfquery name="local.result" datasource="testBeanDao" >
INSERT INTO app.testBean (
Name
)
VALUES (
<cfqueryparam value="#arguments.bean.getName()#" cfsqltype="cf_sql_varchar">
)
</cfquery>
<cfreturn local.result />
</cffunction>
/logic/bean/testBean.cfc
<cfcomponent displayname="testBean" output="false">
<cffunction name="init" access="public" output="false" returntype="testBean">
<cfset super.init() />
<cfset variables.instance.ID = 0 />
<cfset variables.instance.Name = arguments.Name />
<cfreturn this />
</cffunction>
<cffunction name="load" access="public" returntype="any" output="false">
<cfargument name="ID" type="numeric" required="true"/>
<cfargument name="Name" type="string" required="true"/>
<cfset setID(arguments.ID) />
<cfset setName(arguments.Name) />
<cfreturn this />
</cffunction>
<cffunction name="setName" returntype="void" access="public" output="false">
<cfargument name="Name" type="string">
<cfset variables.instance.Name = arguments.Name />
</cffunction>
<cffunction name="getName" returntype="string" access="public" output="true">
<cfreturn variables.instance.Name />
</cffunction>
<cffunction name="setID" returntype="void" access="public" output="false">
<cfargument name="ID" type="numeric" required="true" />
<cfset variables.instance.ID = arguments.ID />
</cffunction>
<cffunction name="getID" returntype="numeric" access="public" output="true">
<cfreturn variables.instance.ID />
</cffunction>
</cfcomponent>
Error Message:
The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
The getName method was not found.
Either there are no methods with the specified method name and argument types or the getName method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
The error occurred in C:/programs/cfusion/wwwroot/cfproject/logic/dao/testDAO.cfc: line 35
Called from C:/programs/cfusion/wwwroot/cfproject/logic/manager/testManager.cfc: line 45
Called from C:/programs/cfusion/wwwroot/cfproject/api/testBeanDaoManager.cfc: line 53
Called from C:/programs/cfusion/wwwroot/cfproject/index.cfm: line 85
33 : )
34 : VALUES (
35 : <cfqueryparam value="#arguments.bean.getName()#" cfsqltype="cf_sql_varchar">
36 : )
37 : </cfquery>
(too long for a comment)
You are calling
var bean = gettestBean(arguments.ID);
which points to gettestBean of /api/testBeanDaoManager.cfc. This one does
var nameManager = createObject('component', 'logic.manager.testManager');
var nameBean = nameManager.getName(arguments.ID);
return nameBean;
but logic.manager.testManager doesn't have any getName function. Even if it had one, you would have to return an instance (the bean), which is kinda misleading for a method called getName.

Edited - some PDFs generated are corrupt - using ColdFusion

Edit - There are some customer accounts that are reporting a $0 balance due on their online accounts but there is an actual balance due. It is with these accounts only that the PDFs will not open. Data import issue at this point?
I have a set of CF functions in which new PDFs are generated from database records and available on user accounts for download or viewing. The code has worked great up until a couple weeks ago, but now the new or old (previous monthly bills) PDFs will not open (corrupt) on the user account pages. The record data has not been changed or modified. Could this be CF update issue or what could have caused files to now generate corrupt? Any help is appreciated.
PDF Analysis of the corrupt PDF files gives:
PDF Errors:
Open file.
0x80410108 - E - The end-of-file marker was not found.
- File: 11118749.pdf
0x8041010A - E - The 'startxref' keyword or the xref position was not found.
- File: 11118749.pdf
0x80410108 - E - The end-of-file marker was not found.
- File: 11118749.pdf
Close file.
CF PDF Generation Code:
<cfcomponent>
<!---***************************************************************************--->
<cffunction name="getBill" access="public" returntype="query">
<cfargument name="billID" required="yes" default="">
<cfquery name="getPayment" datasource="#application.dsnName#" username="****" password="****">
SELECT * FROM ccos_cust_bill
WHERE billID = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.billID#">
</cfquery>
<cfreturn getPayment>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="getCustBills" access="public" returntype="query">
<cfargument name="accountNum" required="yes" default="">
<cfquery name="getCustBills" datasource="#application.dsnName#" username="****" password="****">
SELECT * FROM ccos_cust_bill
WHERE accountNum = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.accountNum#">
ORDER BY billDate DESC, billID DESC
</cfquery>
<cfreturn getCustBills>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="addBill" access="public" returntype="string">
<cfargument name="formvalues" required="yes" default="">
<cfquery name="addBill" datasource="#application.dsnName#" username="****" password="****">
INSERT INTO ccos_cust_bill (billID, accountNum, billDate, dueDate, billTotal)
VALUES (
<cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.formvalues.billID#">,
<cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.formvalues.accountNum#">,
<cfqueryparam cfsqltype="cf_sql_date" maxlength="20" value="#DateFormat(arguments.formvalues.billDate, "yyyy-mm-dd")#">,
<cfqueryparam cfsqltype="cf_sql_date" maxlength="20" value="#DateFormat(arguments.formvalues.dueDate, "yyyy-mm-dd")#">,
<cfqueryparam cfsqltype="cf_sql_decimal" scale="2" maxlength="20" value="#arguments.formvalues.billTotal#">
)
</cfquery>
<cfset addOK = "Y">
<cfreturn addOK>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="getBillPDF" access="public" returntype="query">
<cfargument name="billID" required="yes" default="">
<cfargument name="accountNum" required="yes" default="">
<cfquery name="getPayment" datasource="#application.billsDsnName#" username="****" password="****">
SELECT * FROM ccos_bills
WHERE billID = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.billID#">
AND accountNum = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.accountNum#">
</cfquery>
<cfreturn getPayment>
</cffunction>
<!---***************************************************************************--->
<!---***************************************************************************--->
<cffunction name="getNextDueDate" access="public" returntype="string">
<cfargument name="accountNum" required="yes" default="">
<cfquery name="getNextDueDate" datasource="#application.dsnName#" username="****" password="****" maxrows="1">
SELECT dueDate FROM ccos_cust_bill
WHERE accountNum = <cfqueryparam cfsqltype="cf_sql_integer" maxlength="20" value="#arguments.accountNum#">
AND dueDate >= <cfqueryparam cfsqltype="cf_sql_date" maxlength="20" value="#DateFormat(now(), "yyyy-mm-dd")#">
ORDER BY dueDate
</cfquery>
<cfreturn getNextDueDate.dueDate>
</cffunction>
<!---***************************************************************************--->
</cfcomponent>
CF View PDF Code:
<cfparam name="URL.billID" default="">
<cfset getBillPDF = application.billCFC.getBillPDF('#URL.billID#','#session.accountNum#')>
<cfif getBillPDF.RecordCount GT 0>
<cfoutput query="getBillPDF">
<cfset fileData = "#BinaryDecode(billData, "Base64")#">
<cfheader name="content-disposition" value="inline; filename=#billID#.pdf" />
<cfcontent type="application/pdf" variable="#fileData#" />
</cfoutput>
<cfelse>
You are not authorized to view this bill.
</cfif>
PDF Import into Database
<!--- CCOS Bill PDF Data --->
<cfquery name="deleteData" datasource="#application.billsDsnName#" username="#application.billsDsnUser#" password="#application.billsDsnPass#">
DELETE FROM ccos_bills WHERE billDate < '#DateFormat(DateAdd("d", -180, now()), "yyyy-mm-dd")#'
</cfquery>
<!--- Check to see how many files Exist --->
<cfdirectory action="list" directory="#ExpandPath('.')#\files" name="filelist">
<cfset fileCount = 0>
<cfoutput query="filelist">
<cfif name CONTAINS "ccos_cust_bill_pdf"><cfset fileCount = fileCount + 1></cfif>
</cfoutput>
<!--- Loop over the files and Load the new data --->
<cfloop from="1" to="#fileCount#" index="i">
<cfquery name="insertData" datasource="#application.billsDsnName#" username="#application.billsDsnUser#" password="#application.billsDsnPass#">
LOAD DATA LOCAL INFILE '#Replace(ExpandPath('.'), "\", "\\", "ALL")#\\files\\ccos_cust_bill_pdf#i#.txt' IGNORE
INTO TABLE `ccos_bills`
FIELDS OPTIONALLY ENCLOSED BY '"'
TERMINATED BY '|'
<!---IGNORE 1 LINES--->
(`accountNum`, `billID`, `billDate`, `billData`);
</cfquery>
</cfloop>
<cfquery name="fixbillDate" datasource="#application.billsDsnName#" username="#application.billsDsnUser#" password="#application.billsDsnPass#">
UPDATE ccos_bills SET dateCreated = '#DateFormat(now(), "yyyy-mm-dd")#' WHERE dateCreated IS NULL
</cfquery>
<!---***********************************************************************************--->

How can I call a function in another CFC file from within a query of a function in one cfc file?

I have one cfc file (info.cfc) with multiple functions as shown below.
<cfcomponent output="true" extends="DateFunctions">
<cffunction name="getStatuses" access="remote" returntype="any" output="true" returnformat="plain">
...
</cffunction>
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
<cfquery name="records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due
FROM
dbo.tickets
</cfquery>
</cffunction>
</component>
And the other cfc file (DateFunctions.cfc) containing the a function with two arguments and returning a date.
The DateFunctions.cfc file is as follows:
<cfcomponent output="true" name="DateFunctions"">
<cffunction name="addBusinessDays" access="remote" returntype="any" output="true" returnformat="plain">
<cfargument name="daysToAdd"
required="yes"
type="numeric"
hint="The number of whole business days to add or subtract from the given date">
<cfargument name="date"
required="No"
type="date"
hint="The date object to start counting from.."
default="#NowDateTime#">
...
... <!--- Perform some tasks --->
<cfreturn Date>
</cffunction>
</cfcomponent>
Question: How can I invoke "addBusinessDays" from within the query in (info.cfc) also producing another column of results.
I thought I might have been able to do something like:
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
<cfquery name="records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due,
(
<cfinvoke component="DateFunctions" method="addBusinessDays" returnVariable="Date">
<cfinvokeargument name="daysToAdd" value="#dbo.tickets.Days_Due#">
<cfinvokeargument name="date" value="#dbo.tickets.Start_Date#">
</cfinvoke>
) AS Due_DATE
FROM
dbo.tickets
</cfquery>
</cffunction>
You could do the following with the caveat of there would be additional processing for the loop.
Edit: Per discussion below, updated cfoutput to cfloop
<cffunction name="viewDate" access="remote" returntype="any" output="true" returnformat="plain">
<cfquery name="records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due,
'' as Due_DATE
FROM
dbo.tickets
</cfquery>
<cfset df = createobject("component","DateFunctions")>
<cfloop query="records">
<cfset records.Due_DATE = df.addBusinessDays(Days_Due, Start_Date)>
</cfloop>
<cfreturn records>
</cffunction>
Rather than creating the df object, it should be tied to the this scope. That way the object is created only once. This should make the viewDate function run faster as there is no overhead in creating df.
Also, new is just a cleaner syntax
<cfcomponent>
<cfset this.df = new DateFunctions()>
<cffunction name="viewDate" access="remote" returntype="any" output="false" returnformat="plain">
<cfquery name="Local.records">
SELECT
dbo.tickets.Incident,
dbo.tickets.Start_Date,
dbo.tickets.Days_Due,
CAST(NULL AS datetime)
FROM
dbo.tickets
</cfquery>
<cfloop query="Local.records">
<cfset Local.records.Due_DATE = this.df.addBusinessDays( Local.records.Days_Due, Local.records.Start_Date)>
</cfloop>
<cfreturn Local.records>
</cffunction>
<cfcomponent>

coldfusion create list from query results

I am currently using Binding to grab values from a database. Depending on what the user selects from a pull down it shows the results from the database. Currently I am able to show one result but I need to show multiple results if the query brings back more then 1 value. Here is my current code.
<cffunction name="getServiceType" access="remote" returnType="array">
<cfargument name="CATG_NAME" type="string" required="true">
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<cfquery name="getServiceType" datasource="#dsource#">
select distinct SRTY_NAME
from Somedatabase
where (CATG_SPRS_NAME = <cfqueryparam value="#ARGUMENTS.CATG_NAME#" cfsqltype="cf_sql_varchar"> OR CATG_DEPT_SPRS_NAME = <cfqueryparam value="#ARGUMENTS.CATG_NAME#" cfsqltype="cf_sql_varchar">) AND EVLN_REQD_FLAG IS NOT NULL
order by SRTY_NAME
</cfquery>
<cfloop index="i" from="1" to="#getServiceType.recordcount#">
<cfset result[i][1]=getServiceType2.SRTY_NAME[i]>
<cfset result[i][2]=getServiceType2.SRTY_NAME[i]>
</cfloop>
<cfreturn result>
</cffunction>
This generates the 1st pull down list
<cffunction name="getUnion" access="remote" returnType="array">
<cfargument name="SRTY_NAME" type="string" required="true">
<cfset var result=ArrayNew(1)>
<cfquery name="union_rq" datasource="#dsource#">
select U.UNI_NAME, S.SRTY_NAME
from Somedatabase U JOIN Someotherdatabase S ON U.SRTY_NBR = S.SRTY_NBR
where S.SRTY_NAME = <cfqueryparam value="#ARGUMENTS.SRTY_NAME#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfset result[1]=union_rq.UNI_NAME>
<cfreturn result>
</cffunction>
The first list would have an option list Hotel Training and the second query should show both Maids and Cooks. Right now it only shows Maids. I tried to create a list or another array but have not be able to get it to display the results. Below is my Coldfusion call for the display. It is fine to display with commas between the results like Maids,Cooks
<tr id="union">
<td></td>
<td>Union Attached:
<cfinput name="uni_name"
bind="cfc:servicetype.getUnion({service_type})"
bindonload="false"
/></td></tr>
Any advice would be greatly appreicated.