Cffunction returntype question
I've got a function (below) in a CFC that executes a stored
procedure. The procedure has 2 input parameters and a single output
parameter. I want to cfoutput the value of the output parameter in
the procedure. The procedure does it's job in CF if I don't return
the output parameter. I keep having problems with the
returnvariable type. I've output returntypes of query in the past
without any problem, but never a single calculated value. The value
being output by the procedure is a long integer.
<!--- FUNCTION --->
<cffunction name="myFunctTest" hint="ProcedureTest"
returntype="??????">
<cftry>
<cfstoredproc procedure="myProc" username='#this.user#'
password='#this.pass#' datasource='#this.dSource#'>
<cfprocparam type="Out" cfsqltype="cf_sql_integer"
variable="OutputID"><!--- Output variable I want to return
--->
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER"
value='#this.par1#' dbvarname="myPar1">
<cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR"
value='#this.par2#'dbvarname="myPar2">
</cfstoredproc>
<cfcatch type="any">
<cfreturn "Error in Function...">
</cfcatch>
</cftry>
<cfreturn ??????>
</cffunction>
<!--- FUNCTION CALL --->
<cfinvoke component="cfc.myCFC" method="myFunctTest"
returnvariable="??????">
<cfinvokeargument name="user" value="#myUser#">
<cfinvokeargument name="pass" value="#MyPass#">
<cfinvokeargument name="dSource" value="#myDSource#">
<cfinvokeargument name="par1" value="#Form.MyPar1#">
<cfinvokeargument name="par2" value="#Form.MyPar2#">
</cfinvoke>
Thanks in advance
Roy.
Combine,
Are your stored procedure parameters defined in the same
order you are using them in your CFSTOREDPROC tag? Bear in mind
that the dbvarname attribute is ignored in CF6+.
Similar Messages
-
If I have a cffunction within a cfc that simply does an
update on the DB should I use returntype="void"?
How about not even specifying the returntype?
Thanks!Tend to agree here - if you havea requirement for strong
typing you probably
shouldn't be using coldfusion. These days, it seems we either
want to work
with dynamic languages or more tradiotonal "compiled"
languages. And the
choice for dynamic languages is usually made on "the need for
speed" at
development time - strong typing would seem to run contrary
to this idea.
Btw - even in compiled languages (java, c#) you can still get
type errors at
runtime - compliler cannot catch them all unfortunately. (eg;
cast errors,
null reference errors)
"Hal B. Helms" <[email protected]> wrote in
message
news:f72sfs$los$[email protected]..
> The question is one of whether ANY typing should be
used. The goal of
> typing
> variables is "type safety" -- the assurance that no data
type mismatches
> can
> occur. In a strongly-typed language such as Java or C#,
this happens at
> compile
> time and it's very helpful.
>
> In a weakly-typed language such as ColdFusion or Ruby,
the only time
> type-checking can be done is at run time. This is much,
much less helpful.
> My
> own personal opinion is to omit all typing of variables.
There's so little
> to
> gain and quite a cost involved (beyond the finger
typing).
> -
"The value returned from the addRequirement function is not
of type query" is what I get when I execute the below function.
This works fine in 7, but in 8 I get that error. Any ideas?
<CFFUNCTION NAME="addItem" output="false"
returntype="query">
<CFARGUMENT NAME="userid" TYPE="numeric"
REQUIRED="true">
<CFARGUMENT NAME="title" TYPE="string"
REQUIRED="true">
<cfset var addRequirement = "">
<CFQUERY NAME="addItem" datasource="#variables.dsn#">
INSERT INTO test(userID,title)
VALUES (#ARGUMENTS.userID#,'#arguments.title#')
</CFQUERY>
<cfreturn addItem>
</CFFUNCTION>In addition to the insert not returning a result set, you
have your var declared as 'addRequirement'
but your query name and return value are 'addItem'
If it were me, I'd set the return type to boolean, then set a
var result = 'FALSE'. Wrap the insert query in a CFTRY and if it's
sucessful, set result = 'TRUE' and then return result -
Webservice cffunction returntype="xml" complex datatype problems WSDL
Ho do I create complex data types in my WSDL when using
returntype="xml"??
I have tried a few different things but for the life of me I
cannot figure it out.If you open the Developer Guide of CFMX7
(cfmx7_dev_guide.pdf) page 909, there is a description how to
handle complex data types.
Laksma -
I just picked up coldfusion about a month ago, so my
coldfusion lingo sucks. I have been programming in C++ for over 5
years now and will be using a lot of C++ terminology to help avoid
any confusion. I am writing a cfc function that preforms web
servicing. This function needs to return an object/class that is
defined in another coldfusion function. I can do this without a
problem if I only need to return one instance of this object.
However, I cannot seem to return an array of this object (I need to
return multiple instances of this object, kind of like a query, but
for programming purposes it needs to stay as an object).
It seems that the webservicing function hates my return type.
If I try to make an array of the object, it does not like array or
the object as the return type. However, when I take this function
out of the cfc, and make it a cfm, it gets the array of objects
just fine. So, I think I am having issues with the return type on
the <cffunction> tag. So I came up with the idea of creating
another object which will hold an array of the first object and
using the second object as the return type. Here is some psuedo
code of the function I am working on:
<cffunction name="SelectGames" access="remote"
returntype="ArrayOfGames" output="false">
<!-- arguments --->
<!--- query --->
<cfobject component = "myArray" name>
<cfobject component="games" name="test">
<cfset counter = 0>
<cfloop query="getevents">
<cfset counter = counter + 1>
<cfset test.Game_id = event_id>
<cfset test.gameDate = eventdate>
<cfset test.Starttime = starttime>
<cfset test.Place = place>
<cfset test.Level = level>
<cfset test.Sport = sport>
<cfset test.Gender = division>
<cfset test.Opponent = opponent_id>
<cfset test.Type = type>
<cfset test.Link = spec_name>
<cfset myArray.gamesArray[counter] = test>
</cfloop>
<cfreturn myArray>
</cffunction>
It keeps telling me that it does not recognize the return
type.
Here are examples of the two objects I am using from the 2
dif. cfc files:
<cfcomponent>
<cfproperty name="gamesArray" type="array">
</cfcomponent>
<cfcomponent>
<cfproperty name="Game_id" type="numeric">
<cfproperty name="gameDate" type="date">
<cfproperty name="Starttime" type="string">
<cfproperty name="Place" type="string">
<cfproperty name="Level" type="string">
<cfproperty name="Sport" type="string">
<cfproperty name="Gender" type="string">
<cfproperty name="Opponent" type="string">
<cfproperty name="Type" type="string">
<cfproperty name="Link" type="string">
</cfcomponent>
Feel free to post any questions to clear anything up, I know
this is confusing and I probably did a poor job of explaining my
problem. Also, if I throw this code into a cfm and try to make an
array of games, it works, this is the code I got it to work with:
<cfset myArray = newArray(1)>
<cfloop query="getevents">
<cfset counter = counter + 1>
<cfset test.Game_id = event_id>
<cfset test.gameDate = eventdate>
<cfset test.Starttime = starttime>
<cfset test.Place = place>
<cfset test.Level = level>
<cfset test.Sport = sport>
<cfset test.Gender = division>
<cfset test.Opponent = opponent_id>
<cfset test.Type = type>
<cfset test.Link = spec_name>
<cfset myArray[counter] = test>
</cfloop>
I guess my problem is I do not know how to specify a type for
an array.The return type of this FUNCTION would be returnType="array".
No matter
what kind of data the array contained.
That's what I get for fast proofing.
Ian Skinner wrote:
> I would have to play with your code more if this does
not clear it up
> for you, but lets start with this simple concept first.
>
> You mentioned "typing the array" several times.
ColdFusion is typeless,
> you don't type an array, it is just array. An array of
strings is the
> same as an array of integers which is the same as an
array of objects.
>
> So if you had a function something like this.
>
> <cffunction returnType="array" ...>
> <cfset theArray = arrayNew()>
>
> <cfloop ...>
> <cfset arrayAppend(theArray, newObject)>
> </cfloop>
>
> <cfreturn theArray>
> </cffunction>
>
> The return type of this function would be
returnType="array". No matter what
> kind of data the array contained.
>
> mwiley63 wrote:
>> I just picked up coldfusion about a month ago, so my
coldfusion lingo
>> sucks. I have been programming in C++ for over 5
years now and will
>> be using a lot of C++ terminology to help avoid any
confusion. I am
>> writing a cfc function that preforms web servicing.
This function
>> needs to return an object/class that is defined in
another coldfusion
>> function. I can do this without a problem if I only
need to return
>> one instance of this object. However, I cannot seem
to return an
>> array of this object (I need to return multiple
instances of this
>> object, kind of like a query, but for programming
purposes it needs to
>> stay as an object).
>> It seems that the webservicing function hates my
return type. If I
>> try to make an array of the object, it does not like
array or the
>> object as the return type. However, when I take this
function out of
>> the cfc, and make it a cfm, it gets the array of
objects just fine.
>> So, I think I am having issues with the return type
on the
>> <cffunction> tag. So I came up with the idea
of creating another
>> object which will hold an array of the first object
and using the
>> second object as the return type. Here is some
psuedo code of the
>> function I am working on:
>>
>> <cffunction name="SelectGames" access="remote"
>> returntype="ArrayOfGames" output="false">
>> <!-- arguments --->
>> <!--- query --->
>> <cfobject component = "myArray" name>
>> <cfobject component="games" name="test">
>> <cfset counter = 0>
>> <cfloop query="getevents">
>> <cfset counter = counter + 1>
>> <cfset test.Game_id = event_id>
>> <cfset test.gameDate = eventdate>
>> <cfset test.Starttime = starttime>
>> <cfset test.Place = place>
>> <cfset test.Level = level>
>> <cfset test.Sport = sport>
>> <cfset test.Gender = division>
>> <cfset test.Opponent = opponent_id>
>> <cfset test.Type = type>
>> <cfset test.Link = spec_name>
>> <cfset myArray.gamesArray[counter] = test>
>> </cfloop>
>> <cfreturn myArray>
>> </cffunction>
>>
>> It keeps telling me that it does not recognize the
return type.
>> Here are examples of the two objects I am using from
the 2 dif. cfc
>> files:
>> <cfcomponent>
>> <cfproperty name="gamesArray" type="array">
>> </cfcomponent>
>> <cfcomponent>
>> <cfproperty name="Game_id" type="numeric">
>> <cfproperty name="gameDate" type="date">
>> <cfproperty name="Starttime" type="string">
>> <cfproperty name="Place" type="string">
>> <cfproperty name="Level" type="string">
>> <cfproperty name="Sport" type="string">
>> <cfproperty name="Gender" type="string">
>> <cfproperty name="Opponent" type="string">
>> <cfproperty name="Type" type="string">
>> <cfproperty name="Link" type="string">
>> </cfcomponent>
>>
>> Feel free to post any questions to clear anything
up, I know this is
>> confusing and I probably did a poor job of
explaining my problem.
>> Also, if I throw this code into a cfm and try to
make an array of
>> games, it works, this is the code I got it to work
with:
>> <cfset myArray = newArray(1)>
>> <cfloop query="getevents">
>> <cfset counter = counter + 1>
>> <cfset test.Game_id = event_id>
>> <cfset test.gameDate = eventdate>
>> <cfset test.Starttime = starttime>
>> <cfset test.Place = place>
>> <cfset test.Level = level>
>> <cfset test.Sport = sport>
>> <cfset test.Gender = division>
>> <cfset test.Opponent = opponent_id>
>> <cfset test.Type = type>
>> <cfset test.Link = spec_name>
>> <cfset myArray[counter] = test>
>> </cfloop>
>>
>> I guess my problem is I do not know how to specify a
type for an array.
>> -
Ajax cfc issue -- indeterminent error msg
I have one ajax cfc app that works fine. This app uses the file name from the browse button on the file input object that is passed to my proxy.cfc, which in turn, queries the attachments table in my db to see if this file has already been uploaded for this project. If the file is not there, then I upload it to the server. If it is there, I pop-up an error message to the user giving him/her the date/time it was uploaded and by whom. These values are returned by testing code in the cfc. It works great.
I am now working on another app that will populate a lower-order select box in a hierarchy of select boxes based upon the new value in the current select box that has just been selected. It seems doable, but there is an immediate error that I cannot seem to get past an error thrown by the IE error handler as an unhandled error. This error is a “throw msg” error within the core Adobe code, which I’ve pasted in below:
I have modeled the new app after the one that I have working. In a effort to figure out this cause of this problem, I have even housed it in the original proxy.cfc to eliminate any question about having it in the correct location on the server.
At the current point, I am only trying to return an input value from the app, getAreasRmt. Here are the calling and called code. The line in the calling code that generates the error is the one where I call the cfc function: “alert (‘Rtnd BuGrpID: ‘ + areaProxy.getAreasRmt(….)));”
Calling JS:
getAreasRmt:
This code will eventually pass back a structure containing all of the areas whose Business Group ID is sBuGrpID.
I am running CF8 on a W2003 x64 server with IIS 6.0.
Thanks in advance for any help/suggestioins.
LenFolks,
This is my first attempt to bind a CFC to a <cfselect> so I may be missing something very basic that everyone elses knows.
I've made some progress on this issue, but I'm not sure I'm actually moving forward. After Googling, reviewing CF8 books and searching this site, I have converted this over to binding my CFC to a <cfselect>, which then calls the procedure within the cfc. I've also started using cfdebug and FireBug from time to time to try to gain some insight into what is happening.
But I think that I'm just at a different form of the original error message. Here is the error from the Ajax Debug Log window:
window:global: Exception thrown and not caught (http://192.168.1.100/CFIDE/scripts/ajax/package/cfajax.js, line 798) [Note: 798 could be the loction of the original error. Or not]
info:http: CFC invocation response:{"COLUMNS":["LOCATIONNAME","LOCATIONID"],"DATA":[["CDPG BOARDS",1],["CDPG Boxed Processor",12],["DIJIC",13],["EPSD BOARDS",2],["EPSD SYSTEM",3],["KM-RDV",4],["LAD",5],["MCPD",6],["MWG",7],["New BOARDS",9],["NEW_BIZ-RDV",11],["NPG",10],["OPD",8],["TestBus",14],["Testing ",15]]}
info:http: HTTP GET /PHREDsevenInternal/Templates/hierchy.cfc?method=getLocs&returnFormat=json&argumentCollec tion=%7B%7D&_cf_nodebug=true&_cf_nocache=true&_cf_clientid=999030C7709D5E20E12A17ED431EFB2 A&_cf_rc=0
info:http: Invoking CFC: /PHREDsevenInternal/Templates/hierchy.cfc , function: getLocs , arguments: {}
info:LogReader: LogReader initialized
info:global: Logger initialized.
It is returning the query from the CFC finally. I'm assuming that if there would not have been an error, then the query would have been loaded into the <cfselect> that called it.
Here is the latest version of both sides of the cfc binding:
Call side:
<cfselect bind="CFC:hierchy.getLocs()" bindonload="true" value="LocationID" display="LocationName" name="Location" />
Here is the CFC code:
<cfcomponent output="false">
<!--- Test to see if the passed-in name is in the db already --->
<cffunction name="getLocs" access="remote" returntype="query">
<cftry>
<cfquery name="getLocQry" datasource="PHREDsevenInternalSQL">
SELECT LocationName,LocationID
FROM Locations
ORDER BY LocationName
</cfquery>
<cfcatch type="Any">
<cfdump var="#getLocQry#">
</cfcatch>
</cftry>
<cfreturn getLocQry>
</cffunction>
</cfcomponent>
Question about location of the CFC. I prefer to keep all my CFC's in a CFC directory so that they can be reuseable. I tried both relative and full location methods but neither worked. If it didn't find the CFC, then it would throw an error telling me that it didn't find it, but I could not get the query to run and return the info you see above until I moved it into the directory where the calling cfm lives. Is there some mystical/magically method for letting CF know where it is if it isn't in the invoking directory? I know that if I were invoking a CFC that I would have to use the full path dotted method. I actually did that here but it didn't get me a result back. It just told me that I needed to return a 2D arrary or serialized query, which told me that I wasn't actually running the query even though CF could not find it. Or I think that is what it meant.
I'm at a total loss as how to proceed. I've spent 4 days on this now and need to get this issue resolved.
Thanks again for any suggestions/help on this matter.
Len -
Application.cfc, OnRequestStart, CFInclude
O.K. I'll admit I am feeling a little stupid here but I just
don't understand this. All I wanted to do was include my script
library file using the OnRequestStart function withn
application.cfm. There isn't anything special inthe _ScriptLib.cfm
template. My Application.cfc file looks like this... (Only the
pertinent portions are included)
<CFFUNCTION NAME="onRequestStart" OUTPUT="Yes"
RETURNTYPE="any">
<CFINCLUDE TEMPLATE="_ScriptLib.cfm">
... (other CFSETS and junk like that)
</CFFUNCTION >
<CFFUNCTION NAME="onRequest">
<CFARGUEMENT NAME="targetTemplate" type="String"
required="true" />
<CFINCLUDE TEMPLATE="#arguments.targetTemplate#">
</CFFUNCTION>
My question is why do I need to add the CFArguement tag in
the OnRequest function to include my scripts??? Why doesn't the
CFInclude tag in OnReqMy question is why do I need to add the CFArgument tag in the
OnRequest function to include my scripts???
You don't need to add the cfargument tag to onRequest to
enable you to use cfinclude in OnRequestStart. In this case, the
only musts are:
if you implement the OnRequest method, then it must load the
target-page through a cfargument tag and it must explicitly call
the page through a cfinclude tag.
That makes the Variables scope of the requested page (and its
included pages!) available in OnRequestStart. If a variable is
called x in the requested page, you may just call it x in
OnRequestStart. If you hadn't included the cfargument and cfinclude
tags in OnRequest, or if you didn't iimplement the OnRequest method
at all, the only page variables you would have access to in
OnRequestStart are those in Request scope. -
Issue with autosuggest on a numeric field
I have a form with a CFINPUT that has autosuggest to a cfc.
The cfc runs a query against a varchar field that has only numeric
values. When the match is made and the lis is returned I get an
error (Bind failed for autosuggest CUSTOMER, bind value is not a 1D
array of strings). This only happens with fields that are all
numeric, if the field has any letters or symbols I do not have this
issue.
The data returned is coming back as numeric in scientific
notation (CFC invocation response: [5.159000038E9]) The data is
matching on the phone number and that is what is being returned.
It there a way to correct this issue? Code sample is below.
<cfinput type="text" name="CUSTOMER" size="10"
maxlength="10" value="#CUSTOMER#"
autosuggest="cfc:customerInfo.getCustomerSuggest({DSN},
{cfautosuggestvalue})">
here is the function from the CFC:
<cffunction name="getCustomerSuggest" access="remote"
returntype="array" output="false">
<cfargument name="argDB" type="string" required="yes">
<cfargument name="argCUSTOMER" type="string"
required="yes">
<cfset var myarray = ArrayNew(1)>
<cfquery name="cstInfo" datasource="#argDB#"
maxrows="25">
SELECT customer
FROM custFile
WHERE customer LIKE <cfqueryparam value="#argCUSTOMER#%"
cfsqltype="CF_SQL_VARCHAR">
</cfquery>
<cfloop query="cstInfo">
<cfset arrayAppend(myarray, '#customer# ')>
</cfloop>
<cfreturn myarray>
</cffunction>I don't understand the actual results desired. But I would
make my cffunction returntype a string and get rid of the cfloop
that creates your array. One of my autosuggest cfcs is;
<cffunction name="getJobsearch" access="remote"
returnType="string" output="false">
<cfargument name="term" type="string"
required="false">
<cfset var Jqry = "">
<cfquery name="Jqry" datasource="taxsearchdb">
SELECT J.CompanyName + ' ' + J.CompanyCity + ' ' + C.State +
' ^' + cast(J.JobOrderNumber as varchar) as Jname
FROM jorder J, Companies C
WHERE J.CompanyNumber = C.CompanyRecordNumber and
J.CompanyName LIKE <cfqueryparam cfsqltype="cf_sql_var"
value="#trim(arguments.term)#%">
</cfquery>
<cfreturn ValueList(Jqry.Jname)>
</cffunction> -
Issue with AutoSuggest + UpdateContent
Hi,
Using Spry.Utils.updateContent when I load part of a page
containing an AutoSuggest the AutoSuggest breaks.
Seems like the XML datasource is not fired in that case. If I
put the AutoSuggest code out of the destination DIV it works.
Click here to see what I
mean
I'm using v1.5. Any clue ? Thanks.I don't understand the actual results desired. But I would
make my cffunction returntype a string and get rid of the cfloop
that creates your array. One of my autosuggest cfcs is;
<cffunction name="getJobsearch" access="remote"
returnType="string" output="false">
<cfargument name="term" type="string"
required="false">
<cfset var Jqry = "">
<cfquery name="Jqry" datasource="taxsearchdb">
SELECT J.CompanyName + ' ' + J.CompanyCity + ' ' + C.State +
' ^' + cast(J.JobOrderNumber as varchar) as Jname
FROM jorder J, Companies C
WHERE J.CompanyNumber = C.CompanyRecordNumber and
J.CompanyName LIKE <cfqueryparam cfsqltype="cf_sql_var"
value="#trim(arguments.term)#%">
</cfquery>
<cfreturn ValueList(Jqry.Jname)>
</cffunction> -
I am trying to run a function like:
<cfoutput>#F_name#</cfoutput>
<CFFUNCTION NAME="F_name">
... generates some tables and reports ...
</cffunction>
Instead of the tables, I have a coded string of characters.
Am I missing something here ?
Should the function be in CF component ?
Thanks for help !If your function generates output, then the below would work.
<cfoutput>#F_name()#</cfoutput>
But I'm guessing you're not generating output and just doing
calculations, you need to return the value using something like
<cffunction name="F_name">
<cfset a = 1>
<cfset b = 2>
<cfreturn a + b>
</cffunction> -
Newbie question about component and UDF usage.
This will be the 1st time I'm coding a component and UDF. I
kind of understand the concept but not sure about how to write it
in detail.Such as passing the parameter, etc.
I'm starting to write a user login, verifying users before
allowing them to enter into the app.
So I have 2 fields in my login form, Login and password.
Upon submitting this form, on the actionpage.cfm I'm calling
a component. This is how I call the component:
<CFINVOKE Component="cfc/loginaction"
Method="AuthentiCateUser" ReturnVariable="UserInfo">
Then in my Component I have the following:
<CFCOMPONENT>
<CFFUNCTION Name="AuthentiCateUser" RETURNTYPE="Query"
hint="Use for user login">
<CFARGUMENT Name="login" Type="Structure"
Required="true">
<CFARGUMENT Name="password" Type="Structure"
Required="true">
<!--- checking user authentication --->
<CFQUERY NAME="Authenticate" DATASOURCE="sendfast">
SELECT * FROM tblcustomer WHERE Login = '#Login#' AND
Password = '#Password#'
</CFQUERY>
<CFRETURN AuthentiCateUser>
</CFFUNCTION>
</CFCOMPONENT>
When I run this code, I got error, it said :
The parameter LOGIN to function AuthentiCateUser is required
but was not passed in.
The error occurred in
C:\CFusionMX\wwwroot\KDt_Mod\userloginaction.cfm: line 18
16 : <CFSET
UserLoginInfo["Password"]="#Form.Password#"> 17 : 18 :
<CFINVOKE Component="cfc/loginaction" Method="AuthentiCateUser"
ReturnVariable="UserInfo">
19 :
My question is:
What should I do in order to pass #Form.Login# and
#Form.Password# to my UDF within my component?
I'm using CFMX 6 and Micrisift SQL 8I've applied cfinvokeargument and my login and password were
passed to my component.
But I'm facing new problem: Where should I write my
authentication? should I write user authentication within my
component or
loginaction.cfm (the calling template)
What I mean by authentication is something like this:
<CFIF #Authenticate.RecordCount# IS NOT 0>
<cfset session.CustomerID
="#Authenticate.customerid#">
<cfset session.Name ="#Authenticate.Name#">
<CFCOOKIE NAME="UserLoginIn"
VALUE="12345_pn#Authenticate.customerid#">
<cflocation url="index.cfm?loc=home">
<CFELSE>
<script language="JavaScript">
alert("Username/password is not found, plese try again");
history.go(-1);
</script>
<cfabort>
</CFIF>
If I keep this code in my loginaction.cfm what is returned
from my function is not recognized by the component, the error said
Authenticate.RecordCount is not recognized.
Also I'm still confuse with what should I put in the
RETURNTYPE. If I put query, it gave me error, also, what is
returned by CFRETURN.
This is my component:
<CFCOMPONENT>
<CFFUNCTION Name="AuthentiCateUser" RETURNTYPE="Query"
hint="Use for user login">
<CFARGUMENT Name="login" Type="Structure"
Required="true">
<CFARGUMENT Name="password" Type="Structure"
Required="true">
<!--- checking user authentication --->
<CFQUERY NAME="Authenticate" DATASOURCE="sendfast">
SELECT * FROM tblcustomer WHERE Login = '#Login#' AND
Password = '#Password#'
</CFQUERY>
<CFRETURN AuthentiCateUser>
</CFFUNCTION>
</CFCOMPONENT> -
ColdFusion.Ajax.submitForm ResultHandler Question
I am developing an CF Ajax based solution in which I use
ColdFusion.Ajax.submitForm to pass form values to a CFC for
processing via Java Script. My question is related to the Java
Script resultHandler and whether or not there is an easy way to
return the results from the CFC to handler.
My Java Script looks like this...
function InsertRec() {
ColdFusion.Ajax.submitForm('MyForm',
'service.cfc?method=InsertRec', resultInsertHandler,
resultErrorHandler);
My CFC looks like this.. (condensed)
<cffunction name="insertRec" access="remote" output="no"
returntype="numeric">
<cfargument name="NAME">
<cfargument name="Phone">
<cfquery name="recInsert" datasource="#request.DS#">
<cfset NEW_NUMBER = updatedNum( )> <-- Getting new #
from another table via CFC
INSERT INTO MYTABLE
(NUMBER, NAME, PHONE)
Values (' #NEW_NUMBER# ' , ' #ARGUMENTS.NAME# ' , '
#ARGUMENTS.PHONE# ' )
</cfquery>
<cfreturn NEW_NUMBER>
</cffunction>
What I'm trying to do is return the value of NEW_NUMBER from
the CFC back to resultInsertHandler so I can use it in a Java
Script alert msg. Any ideas or thoughts would be greatly
appreciated.
Regards
Martin FranklinMMFranklin wrote:
> What I'm trying to do is return the value of NEW_NUMBER
from the CFC back to
> resultInsertHandler so I can use it in a Java Script
alert msg. Any ideas or
> thoughts would be greatly appreciated.
Something like this I would presume.
function resultInsertHandler(returnMsg)
alert(returnMsg); -
Ok, I'm working on my first CFC, and having some problems.
The code I have
so far is:
<cfcomponent displayname="duplicate" hint="Duplicates
local club
tournaments">
<!--- This function retrieves all customers from the
database --->
<cffunction name="getinfo"
hint="Gets all tournament info from the database">
<cfquery name="DuplicateTournamentList"
datasource="SalleBoise">
select * from clubtournaments
where TournID=#session.tid#
</cfquery>
<cfset NewEventName=DuplicateTournamentList.TournName>
<cfset NewEventDesc=DuplicateTournamentList.TournDesc>
<cfset
NewDateTime=dateadd("m",2,dateformat(TournDateTime,"mm/dd/yyyy"))>
<cfset
NewTournFoil=DuplicateTournamentList.TournFoilEvent>
<cfset
NewTournEpee=DuplicateTournamentList.TournEpeeEvent>
<cfset NewType=DuplicateTournamentList.EventType>
<cfset
NewDuplicate=DuplicateTournamentList.TournDuplicated>
<cfquery name="NewTourn" datasource="SalleBoise">
insert into clubtournaments
(TournName,TournDesc,TournFoilEvent,TournEpeeEvent,EventType,TournDateTime,TournDuplicate d)
values
(#NewEventName#,#NewEventDesc#,#NewTournFoil#,#NewTournEpee#,#NewType#,#NewDateTime#,#NewD uplicate#)
</cfquery>
<cfquery name="UpdateOldTourn" datasource="SalleBoise">
update clubtournaments
set TournDuplicated=1
where TournID=#session.tid#
</cfquery>
</cffunction>
</cfcomponent>
And I'm calling it with:
<cfinvoke component="duplicate.cfc" method="getinfo">
And I'm getting:
Error Occurred While Processing Request
Could not find the ColdFusion Component or Interface
duplicate.cfc.
Ensure that the name is correct and that the component or
interface exists.The 1 question I have with your code that is different than
mine is the
query. Mine, I had hoped would take the info from the
previous event,
and add a number of months to it before adding it into the
table.
It looks like yours simple duplicates the event without
changing that
date, correct?
Azadi wrote:
> first, rtfm about <cfinvoke> tag. the component
attribute needs a
> dot-delimited path to your cfc, i.e. if your cfc is
stored in a
> components folder under web root and your calling
template is also in
> the webroot: component="components.duplicate"
>
> then, it is not a good practice to access outside
variables from within
> the cfc - in your case you are accessing session vars.
you better pass
> them in to your cfc as arguments when you invoke it and
have
> <cfargument> tags in your function that accept
them (see code at the bottom)
>
> <cfinvoke component="components.duplicate"
method="getinfo"
> tid="#session.tid">
>
> or
>
> <cfinvoke component="components.duplicate"
method="getinfo">
> <cfinvokeargument name="tid"
value="#session.tid#">
> </cfinvoke>
>
> then, variable scoping - always scope any cfc vars with
var: <cfset var
> somevar = something>. this will help you avoid
variables confusion when
> your calling page has vars with same names.
>
> then, even inside cfc, you should always use
<cfqueryparam> tags in your
> queries.
>
> as for your queries - the 3 of them can be combined
easily into one.
>
> so your function in the end can look something like:
> [note: query syntax is db-specific; check your db for
correct syntax to use]
>
> <cffunction name="getinfo"
> hint="Gets all tournament info from the database"
returntype="boolean"
> output="no">
> <cfargument name="tid" required="yes"
type="numeric">
> <cfset var DuplicateTournamentList = "">
> <cfset var result = true>
> <cftry>
> <cfquery name="DuplicateTournamentList"
datasource="SalleBoise">
> INSERT INTO clubtournaments
> (TournName, TournDesc, TournFoilEvent, TournEpeeEvent,
EventType,
> TournDateTime, TournDuplicated)
> SELECT TournName, TournDesc, TournFoilEvent,
TournEpeeEvent, EventType,
> TournDateTime, 1 AS TournDuplicated
> FROM clubtournaments
> WHERE TournID = <cfqueryparam
cfsqltype="cf_sql_integer"
> value="#arguments.tid#">
> </cfquery>
> <cfcatch type="any">
> <cfset result = false>
> </cfcatch>
> </cftry>
> <cfreturn result />
> </cffunction>
>
> and your cfinvoke something like the examples above.
>
> hth
>
>
> Azadi Saryev
> Sabai-dee.com
>
http://www.sabai-dee.com/ -
Hi,
I have a form where I fill a customer-no. into an input field and get the customer name using databinding.
This works fine, but when I put non-numeric values into customer-no I get following error:
Error invoking CFC customer.cfc : The CUST_ID argument passed to the getcustomer function is not of type numeric. [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
The message is correct, but how can I avoid to run the getcustomer function when the value is not numeric?
Here is my code:
The form:
<cfinput type="text" name="customer_no" style="width:140;background-color:yellow" maxlength="10" validate="integer" validateat="onblur" message="Customer No. format is integer">
<cfinput type="text" name="customer_name" style="width:170" maxlength="200" bind="cfc:customer.getcustomer({customer_no})" readonly="yes">
customer.cfc:
<cfcomponent >
<cffunction name="getcustomer" access="remote" returntype="string" output="yes" >
<cfargument name="cust_id" type="numeric" required="true" >
<cfset r_customer = "">
<cfquery name = "select_customer" dataSource = "x">
SELECT name
FROM customer
WHERE id = <cfqueryparam cfsqltype="cf_sql_numeric" value="#arguments.cust_id#" >
</cfquery>
<cfreturn r_customer>
</cffunction>
</cfcomponent>biene22 wrote:
The message is correct, but how can I avoid to run the getcustomer function when the value is not numeric?
That is a trick question! The attribute bind="cfc:customer.getcustomer({customer_no})" implies that the function will run automatically, whether or not customer_no is numeric. -
Cffunction - Accepting and Returning PDFs in memory
Hello,
This is something that I should probably know by now in my CF career, but up until now I have never thought/had to do this type of thing.
I have defined a couple functions that I would like to handle accepting, manipulating, and returning PDFs in memory. What data types should I be using for accepting and returning the PDF in memory between functions? I would prefer to stay away from "any" if possible, but let me know if that is the only choice.
<cffunction name="AddMeUhWaddaMak" returntype="any" access="public" output="no">
<cfargument name="src" type="any" required="yes">
<cfargument name="name" type="string" required="no">
<cfpdf action="addWatermark"
source="#arguments.src#"
name="#arguments.name#"
...>
<cfreturn arguments.name>
</cffunction>Thanks again for the advice. I was doing a little tinkering around with isPDFObject() just to see how it works and came to another question. See below..
<cfdocument format="pdf" name="test2">
test
</cfdocument>
<cfdump var="#isPDFObject(test2)#"><cfabort>
The result says "NO", even though when I dump out "test2" it shows up as binary.
Maybe you are looking for
-
Can I have more than one version of Reader on the same machine?
I'm running Reader 8 because I like the user interface better than the more recent versions. I'd like to also install the latest version only for some integrated tools that require it for use with AIR. Can I have both installed? I don't see any op
-
I started a book with 100 pages, but reduced it to 75 by deleting some pages. When i completed the book & tried to buy it a box pops up saying I have some frames that need photos. I've checked the book over & over & cannot find any pages like that. H
-
Steps to sync my iPad after replacing my PC hard drive
My laptop that I sync my iPad with is acting up and I am either going to format and reinstall win7 or possible replace the hard drive and reinstall win7. Do I need to do anything before I wipe out my hard drive with what I currently have synced with
-
ive been a user for awhile and the one feature that ive always wanted to use is the fax feature when printing. has anyone got this to work? can anyone walk me thru this? thanks!
-
IPhone 1.0.1 update is slow!
Has anyone noticed that with the new update, the phone takes ~10 seconds to wake up? It doesn't respond to the unlock soft button or the physical buttons. This is all new since I updated the system yesterday.