Cffunction valitation error
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.
Similar Messages
-
"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 -
Why setting var in CFFUNCTION causes error
As far as my knowledge goes, the BEST practise when setting
local variable inside a CFFUNCTION is to use the word "var" in
front of the variable name, for example: <CFSET var
myVariable="whatever">
I'm doing it now and all I get is an error message saying:
Error invoking CFC name_of_cfc:local variable myVariable on
line 60 must be grouped at the top of the function body!
I'm using CF8 and I need to use cfswitch within the
cffunction, so when I do <cfcase value="SomeValue"><cfset
var myVariable="TheValue"></cfcase> etc I got that error.
When I tested with just CFSET var MyVariable="TheVariable"
with no cfswitch/cfcase I still get that error
when I took out the word "var" from cfset, I have no error, I
put these variables directly after my cfarguments. Does anyone know
why this is happening to me?
I thought if I don't use the "var" word for my variable set
within cffunction there will be possibilities when later on setting
up another variables outside this function and if the name happen
to be the same, will override each other and causing disaster to my
application.
Please help!!mega_L wrote:
> As far as my knowledge goes, the BEST practise when
setting local variable
> inside a CFFUNCTION is to use the word "var" in front of
the variable name, for
> example: <CFSET var myVariable="whatever">
Yes, this is the best practice to make the variable local to
the
function. But you only need to use the var keyword once when
you define
the variable. And you must define the local variables with
the var
keyword at the very beginning of the function body. The only
content
allowed before this happens are the argument definitions,
i.e. the
<cfargument ...> tags.
If you have a variable that you don't need to use, you just
need to
define it with a default and|or dummy value in the beginning
of the
function. Then you can set it's value appropriately later in
the
function when it is required. This is often done with query
tag return
variables.
I.E.
<cffunction name="myQryFunction"...>
<cfargument name="someArgument"...>
<cfset var localQry = "">
<cfquery name="localQry"...>
SQL
</cfquery>
<cfreturn localQery>
</cffunction>
Because of this necessity to define all local variables at
the beginning
of the function, a lot of developers use a standard where
they define a
local structure. They can then just append new keys and
values to this
local structure throughout the function. Personally I don't
see much
advantage to doing this, but to each his|her own.
I.E.
<cffunction name="myQryFunction"...>
<cfargument name="someArgument"...>
<cfset var local = structNew()>
<cfset local.something = "FooBar">
<cfreturn local.something>
</cffunction> -
Form Validation - Error Trapping Not Working.
Hi,
I'm a Coldfusion beginner desperately trying to get along with some database work for my site and have come across an annoying error that I just can't solve! I'm sure I'm missing something really basic - I just can't for the life of me figure out what it is!
Basically, I have a form for users to sign-up. I have introduced several cfif statements and a basic CAPTCHA system to trap errors. If any errors are submitted then they should be displayed in a cfwindow. This process works fine until I specify the form action - after which it is completely ignored and the form contents are written to the database without any validation taking place. Even without specifying the form action the errors won't show in Internet Explorer.
I really would appreciate any help - it's driving me crazy!
Thanks in advance,
Tom.
Here is the code:
<cfinclude template="CFIDE/headertemplate.cfm">
<!-- RANDOM NUMBER GENERATOR FOR CAPTCHA -->
<cffunction name="makerandom" returnType="string" output="false">
<cfset var chars = "23456789ABCDEFGHJKMNPQRSTW">
<cfset var length = randRange(4,6)>
<cfset var result = "">
<cfset var i = "">
<cfset var char = "">
<cfscript>
for(i=1; i <= length; i++) {
char = mid(chars, randRange(1, len(chars)),1);
result&=char;
</cfscript>
<cfreturn result>
</cffunction>
<!-- ERROR TRAPPING -->
<cfset showForm = true>
<cfparam name="form.email" default="">
<cfparam name="form.artistname" default="">
<cfparam name="form.city" default="">
<cfparam name="form.postcode" default="">
<cfparam name="form.pass" default="">
<cfparam name="form.captcha" default="">
<cfparam name="form.captchahash" default="">
<cfparam name="form.terms" default="">
<cfif isDefined("form.send")>
<cfset errors = "">
<cfif len (form.email) LT '4'>
<cfset errors = errors & "You must include a valid e-mail address.<br />">
</cfif>
<cfif find('.',form.email) is '0'>
<cfset errors = errors & "Your E-mail features no . symbol.<br />">
</cfif>
<cfif find('@',form.email) is '0'>
<cfset errors = errors & "Your E-mail features no @ symbol.<br />">
</cfif>
<cfif not len(trim(form.artistname))>
<cfset errors = errors & "You must include your name.<br />">
</cfif>
<cfif not len(trim(form.city))>
<cfset errors = errors & "You must include your city.<br />">
</cfif>
<cfif not len(trim(form.postcode))>
<cfset errors = errors & "You must include your postcode.<br />">
</cfif>
<cfif not len(trim(form.pass))>
<cfset errors = errors & "You must specify a password.<br />">
</cfif>
<cfif len(form.pass) LT '6'>
<cfset errors = errors & "Password must be between 6 and 10 characters.<br />">
</cfif>
<cfif hash(ucase(form.captcha)) neq form.captchahash>
<cfset errors = errors & "You did not enter the correct Captcha text.<br />">
</cfif>
<cfif not len(trim(form.terms))>
<cfset errors = errors & "You must agree to our Terms and Conditions.<br />">
</cfif>
<cfif errors is "">
<cfset showForm = false>
</cfif>
</cfif>
<cfif showForm>
<cfset captcha = makerandom()>
<cfset captchahash = hash(captcha)>
<cfoutput>
<h1>Artist Sign-Up</h1>
<p>Your details are required for sign-up. Mandatory fields are indicated with a *.</p><br/><br/>
<cfif isDefined("errors")>
<cfwindow name="formerrors"
title="Form Errors"
width="450"
height="250"
modal="true"
initshow="true"
center="true"
closable="true"
minheight="200"
minwidth="200">
<center><b>Please correct the following errors and re-submit the form:</b><br /><br/>#errors#
<br/><a href="javascript:ColdFusion.Window.hide('formerrors');">Close Window</a>
</center>
<br/></cfwindow>
</cfif>
<!-- FORM CONTENTS -->
<cfform action="artist_insert.cfm" method="post">
<table class="signup">
<tr>
<td class="noborder" width="200">
<label for="email">E-Mail Address*:</label>
</td>
<td class="noborder" width="156">
<input type="text" name="email" class="textbox" value="<cfoutput><cfif IsDefined("URL.email")>#URL.email#<cfelse></cfif></cfoutput>"/>
</td>
<td class="noborder">
<cftooltip autoDismissDelay="9999" tooltip="This needs to be a valid e-mail so that<br/> promoters can get in contact with you. <br/>If several people will be using this<br/> account then try and make it a shared<br/> address."><img src="pics/i.jpg" alt="info" border="1" /></cftooltip>
</td>
</tr>
<tr>
<td class="noborder" width="200">
Your Password* (6 to 10 chars.):
</td>
<td class="noborder">
<input type="password" class="textbox" name="pass" maxlength="10"/>
</td>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder" >
Artist/Band Name*:
</td>
<td class="noborder">
<input type="text" class="textbox" name="artistname" />
</td>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder">
City*:
</td>
<td class="noborder">
<input type="text" class="textbox" name="city" />
</td>
<td class="noborder">
<cftooltip autoDismissDelay="9999" tooltip="Entering your locational details enables Gig<br/>Digger to find the events and promoters<br/>in your area. Try specifying a well known<br/>city nearby for the best results."><img src="pics/i.jpg" alt="info" border="1" /></cftooltip>
</td>
</tr>
<tr>
<td class="noborder">
Postcode*:
</td>
<td class="noborder">
<input type="text" class="textbox" name="postcode" maxlength="8"/>
</td>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder">
Your Contact Number:
</td>
<td class="noborder">
<input type="text" class="textbox" name="contact" maxlength="14"/>
</td>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder">
</td>
</tr>
<tr>
<tr>
<td class="noborder" valign="top" width="200">Please enter the CAPTCHA text in the box below*: </td>
<td class="noborder" align="left">
<center><cfimage action="captcha" width="156" height="50" text="#captcha#" border="1">
<input type="hidden" name="captchaHash" value="#captchaHash#"></center>
</td>
<td class="noborder" valign="top">
<cftooltip autoDismissDelay="9999" tooltip="This is here to ensure that<br/>you're human. It stops abuse <br/>of the site and makes it a safer <br/>place for us all."><img src="pics/i.jpg" alt="info" border="1" /></cftooltip>
</td>
</tr>
<tr>
<td class="noborder">
</td>
<td class="noborder" align="right"><font size="-2"><b><a href="javascript:location.reload(false)">Refresh Page</a></b></font>
</td>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder"></td>
<td class="noborder"><input type="text" name="captcha" class="textbox"></td>
</tr>
<tr>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder" width="170">Please check this box to confirm that you agree<br/> to our <b><a href="termsandconditions.cfm">Terms and Conditions</a></b>*.
</td>
<td class="noborder">
<input type="checkbox" class="textbox" name="terms" /></td>
</tr>
<tr>
<td class="noborder">
</td>
</tr>
<tr>
<td class="noborder">
</td>
<td class="noborder" align="center">
<cfinput type="image" src="pics/submit.png" name="send" value="Submit" validate="submitonce" border="1">
</td>
</tr>
</table>
</cfform><br/>
</cfoutput>
<cfelse>
<cfoutput>
Thank you for submitting your details, #form.name#. You may now log in with your e-mail and password.
</cfoutput>
</cfif>
</td>
</tr>
</table>
<!-- FOOTER START -->
</body>
</html>
ARTIST INSERT PAGE - artist_insert.cfm
<cfquery datasource="071907cs07to">
INSERT INTO Artist( Nsudate,
Nemail,
Npass,
Nname,
Ncity,
Npostcode,
Ncnumber
VALUES( ( #Now()# ),
'#Trim(form.email)#',
'#Trim(form.pass)#',
'#Trim(form.artistname)#',
'#Trim(form.city)#',
'#Trim(form.postcode)#',
'#Trim(form.contact)#'
</cfquery>In addition to BreakawayPaul's answer.
You are making it very difficult to troubleshoot your if/else logic because your code includes all the display stuff. Since you're a self proclaimed beginner, you might want to try another approach.
Save your old page and start a new one from scratch. Solve all your logic problems first. Display what you need to see with the cfdump tag.
Here are some hints to make the whole thing easier.
1. In your cfform, use the validate and required attributes to catch errors earlier.
2. You don't have to cfparam every form field. The form has either been submitted to it hasn't. If it has, all the fields will be there with the possible exception of checkboxes or radio button, if nothing was selected. -
public function addPriceRow():void{
var tempPrice:Object= new Object();
tempPrice = price_RO.init();
this.price_dg.dataProvider = tempPrice;
this.price_dg.editable = true;
this.price_dg.setFocus();
private function renderPrice():String{
return String( ); --> here should be the calculations
<mx:DataGrid id="price_dg" x="10" y="28" width="590"
height="84">
<mx:columns>
<mx:DataGridColumn headerText="Quantity"
dataField="qty"/>
<mx:DataGridColumn headerText="Piece"
dataField="piece"/>
<mx:DataGridColumn headerText="Product"
dataField="product"/>
<mx:DataGridColumn headerText="fee" dataField="fee"/>
<mx:DataGridColumn headerText="Total" dataField="total"
labelFunction="renderPrice" editable="false"/>
</mx:columns>
</mx:DataGrid>
<mx:Button x="385" y="0" label="Add Row"
click="addPriceRow()"/>
<mx:Button x="494" y="0" label="Delete Row"/>
Hi All,
I'm using coldfusion and flex2 in my app.
Let's said that I'm creating a datagrid like a shopping card
with Add and
delete buttons.
When I add a item, I create a new row and initializing my
object from the
cfc with defaul values but they dont show in the datagrid.
Also I have a total field, I'm using labelFunction but how
can I get the
value of the other columns to calculate the total ((qyt *
piece) + fee))
I'm new in flex.. please help.
Any links?
Tks
JFBhi Tracy,
As you see I'm trying to use datagrid for input data.
I can't pass the initial values from my init method in the
cfc, I try struct
and still not working
Do you know why?
Here is the code...
<cfscript>
//Initialize the CFC with the default properties values.
variables.priceid = 0;
variables.estimateid = 0;
variables.qty = 0;
variables.piece = 0;
variables.productid= 0;
variables.fee= 0;
variables.total = 0;
</cfscript>
<cffunction name="init" output="false"
returntype="any">
<cfset request.tempStruc = StructNew()>
<cfloop collection="#variables#" item="i">
<cfset request.tempStruc[#i#] = variables[#i#]>
</cfloop>
<cfreturn request.tempStruc>
</cffunction>
The Error is: Type Coercion failed: cannot convert
mx.utils::ObjectProxy@1c90e7c1 to
mx.collections.ArrayCollection
I need to pass these before I can play with the items.
Tks
JFB
"ntsiii" <[email protected]> wrote in message
news:f4pmkr$4h4$[email protected]..
> Hmm, does this work at all? You are setting the entire
dataProvider to
> the
> newly initialized new item object. That should result in
a single row,
> assuming price_RO.init(); returns a valid dataProvider
collection.
>
> You want instead to use the dataProvider API to add the
new item.
>
> You are not showing a dataProvider assignment in the
dataGrid. What is
> the
> dataProvider?
>
> Regarding labelFunction(), the correct method signature
is:
> labelFunction(item:Object, column:DataGridColumn):String
>
> "item" is a reference to the *entire* item object, so
contains the values
> for
> all the properties in the curent item.
>
> "column" is a refernce to the DataGridColumn, so you can
use that to
> determine
> what to return. This lets you have a single
labelFunction for multiple
> columns.
>
> Tracy
> -
Cffunction, onSessionEnd throwing an error, please help
Hello;
I am using an application.cfc file to run my web site. I
added an argument for onmissingtemplate and when I did that, it
made my onSessionEnd statement throw an error:
this is my statement:
<cffunction name="onSessionEnd" returnType="void">
<cfargument name="theSession" type="struct"
required="true">
<cfset var duration =
dateDiff("s",arguments.theSession.created,now())>
<cflog file="#THIS.name#" text="Session lasted for
#duration# seconds.">
</cffunction>
and this is the error:
Invalid CFML construct found on line 85 at column 1.
ColdFusion was looking at the following text:
<
The CFML compiler was processing:
< marks the beginning of a ColdFusion tag.Did you mean LT
or LTE?
The error occurred in C:\Websites\4npp8b\Application.cfc:
line 85
83 : </cfcomponent>
84 :
85 : <cffunction name="onSessionEnd" returnType="void">
86 : <cfargument name="theSession" type="struct"
required="true">
87 : <cfset var duration =
dateDiff("s",arguments.theSession.created,now())>
I don't know if this will make a difference, but here is my
onsessionstart function:
<cffunction name="onSessionStart" returntype="any"
output="true">
<cfset SESSION.created = now()>
</cffunction>
I can't figure out what I did wrong to make it throw that
error. Any ideas?
CFmongernever mind, I figured it out. sorry to bother.
-
The argument TEAM passed to function SearchRes() is not of type numeric.
If the component name is specified as a type of this argument, the reason for this error might be that a definition file for such component cannot be found or is not accessible.
The error occurred in C:\Inetpub\wwwroot\search.cfc: line 4
2 :
3 : <cffunction name="SearchRes" access="public" returntype="query">
4 : <cfargument name="DSN" type="string" required="yes">
5 : <cfargument name="Role" type="string" required="no">
6 : <cfargument name="Team" type="numeric" required="no">
Please look at the above error...any help app...
code ------------------------->
<cfcomponent hint="This cfc does search...">
<cffunction name="SearchRes" access="public" returntype="query">
<cfargument name="DSN" type="string" required="yes">
<cfargument name="Role" type="string" required="no">
<cfargument name="Team" type="numeric" required="no">
<cfargument name="Level" type="numeric" required="no">
<cfargument name="zone" type="numeric" required="no">
<cfargument name="Dept" type="numeric" required="no">
<cfargument name="location" type="numeric" required="no">
<cfargument name="csgid" type="string" required="no">
<cfargument name="status" type="string" required="no">
<cfargument name="filter" type="string" required="no">
<cfargument name="bosseid" type="string" required="no">
<cfdump var="#arguments#">
<cfquery datasource="#arguments.DSN#" name="SearchRes">
Select
r.First_name,
r.Last_name,
r.EID,
r.tech_id,
r.title,
r.hire_date,
r.rehire_date,
l.location,
d.department
from
OPS$RMS.REF_resource r,
OPS$RMS.Ref_department d,
OPS$RMS.REF_Location l
where
r.location_code = l.location_code
And r.department_code = d.department_code
<cfif arguments.role neq "">
And r.role_code = '#arguments.role#'
</cfif>
<cfif arguments.Team neq "">
And r.team_code = #arguments.team#
</cfif>
<cfif arguments.level neq "">
And r.level_code = #arguments.level#
</cfif>
<cfif arguments.zone neq "">
--And r.zone_code = #arguments.zone#
</cfif>
<cfif arguments.dept neq "">
And r.department_code = #arguments.dept#
</cfif>
<cfif arguments.location neq "">
And r.location_code = #arguments.location#
</cfif>
<cfif arguments.csgid neq "">
And r.csg_operator_id like '#arguments.csgid#%'
</cfif>
<cfif arguments.status neq "">
And r.status = '#arguments.status#'
</cfif>
<cfif arguments.filter neq "">
And
r.EID = '#arguments.filter#%'
OR r.First_name like '#arguments.filter#%'
OR r.last_name like '#arguments.filter#%'
OR r.tech_id like '#arguments.filter#%'
</cfif>
<cfif arguments.bosseid neq "">
And r.boss_id = '#arguments.bosseid#%'
</cfif>
</cfquery>
<cfreturn SearchRes>
</cffunction>
</cfcomponent>craigkaminsky wrote:
Might not be an issue but, while your Team variable can be null, the cfargument tag types the variable as a numeric value (as opposed to any or whatever). Depending on what you're supplying this could be a source of the error.
As mentioned we would have to see the code. But that could well be the problem. There is really no concept of a "null" form field. If you are passing in the values of text fields, empy fields will be treated as an empty string "". Since an empty string is not numeric, it would cause exactly the error you are describing.
<!--- simulate an empty form field ---->
<cfset form.someField = "" />
<cfoutput>#test(form.someField)#</cfoutput>
<cffunction name="test" returntype="string">
<cfargument name="someValue" type="numeric" />
<cfreturn "okay"/>
</cffunction> -
I have taken the cfdump for tmpqry and it shows all data for
the range ( No error at this step ) . But when we exceute this
dbquery we get below mentioned error .
<cfquery name="qry" dbtype="query" >
SELECT *
FROM tmpqry
ORDER BY #arguments.colSort# ASC
</cfquery>
senerio:
I am using createobject to create a reference for component
and call MDArraySort function in the cfc and getting this error .
'The system has attempted to use an undefined value, which
usually indicates a programming error, either in your code or some
system code.
Null pointer is undefined.... '
i am using this code in a cfc file.
<cffunction name="MDArraySort" Returntype="query"
access="public" >
<cfargument name="colArray" type="array"
required="true">
<cfargument name="colNames" type="string"
required="true">
<cfargument name="colSort" type="string"
required="true">
<cfargument name="sensorIDs" type="string"
required="true">
<cfscript>
var tmpqry = Querynew(arguments.colNames);
var qRow = QueryAddRow(tmpqry, Arraylen(arguments.colArray)
</cfscript>
<cfloop from="1" to="#Arraylen(arguments.colArray)#"
index="qRowIndex">
<cfscript>
sIndexinSensorIDs = colArray[qRowIndex]["SENSOR"]&"##";
Temp_readin_code =
colArray[qRowIndex]["READING_CODE"]&"##";
QuerySetCell(tmpqry, 'SENSOR', sIndexinSensorIDs,
qRowIndex);
QuerySetCell(tmpqry,
'TYPE',javacast('String',colArray[qRowIndex]["TYPE"]), qRowIndex);
QuerySetCell(tmpqry, 'TIMESTAMP2',
LSParseDateTime(colArray[qRowIndex]["TIMESTAMP2"]), qRowIndex);
QuerySetCell(tmpqry,
'ORDER_BY_PARAM',javacast('String',colArray[qRowIndex]["ORDER_BY_PARAM"]),
qRowIndex);
QuerySetCell(tmpqry, 'READING_CODE',Temp_readin_code ,
qRowIndex);
QuerySetCell(tmpqry,
'READING',javacast('String',colArray[qRowIndex]["READING"]),
qRowIndex);
QuerySetCell(tmpqry,
'PK_READING',javacast('String',colArray[qRowIndex]["PK_READING"]),
qRowIndex);
QuerySetCell(tmpqry,
'ALARM_STATUS',javacast('String',colArray[qRowIndex]["ALARM_STATUS"]),
qRowIndex);
QuerySetCell(tmpqry, 'DURATION',
javacast('String',colArray[qRowIndex]["DURATION"]), qRowIndex);
QuerySetCell(tmpqry,
'DESCRIPTION',javacast('String',colArray[qRowIndex]["DESCRIPTION"]),
qRowIndex);
</cfscript>
</cfloop>
<cfquery name="qry" dbtype="query" >
SELECT *
FROM tmpqry
ORDER BY #arguments.colSort# ASC
</cfquery>
<cfreturn qry >
</cffunction>
It is working fine for some date range and and getting above
mentioned error in sone situation .Hi All ,
Thank you for your support ,
Finally i have fix the issue using some changes in my
function in cfc .
<cffunction name="MDArraySort" Returntype="query"
access="public" >
<cfargument name="colArray" type="array"
required="true">
<cfargument name="colNames" type="string"
required="true">
<cfargument name="colSort" type="string"
required="true">
<cfargument name="sensorIDs" type="string"
required="true">
<cfscript>
//Declare variable collection used in function as local
--->
var tmpqry =
Querynew(arguments.colNames,"CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_DATE,CF_SQL_VARCHAR,CF_ SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR");
var qRow = QueryAddRow(tmpqry,
Arraylen(arguments.colArray));
</cfscript>
<cfloop from="1" to="#Arraylen(arguments.colArray)#"
index="qRowIndex">
<cfscript>
// Populate the query table
QuerySetCell(tmpqry, 'SENSOR',
colArray[qRowIndex]["SENSOR"], qRowIndex);
QuerySetCell(tmpqry,
'TYPE',arguments.colArray[qRowIndex]["TYPE"], qRowIndex);
QuerySetCell(tmpqry, 'TIMESTAMP2',
LSParseDateTime(arguments.colArray[qRowIndex]["TIMESTAMP2"]),
qRowIndex);
QuerySetCell(tmpqry,
'ORDER_BY_PARAM',arguments.colArray[qRowIndex]["ORDER_BY_PARAM"],
qRowIndex);
QuerySetCell(tmpqry, 'READING_CODE',
colArray[qRowIndex]["READING_CODE"] , qRowIndex);
QuerySetCell(tmpqry,
'READING',arguments.colArray[qRowIndex]["READING"], qRowIndex);
QuerySetCell(tmpqry,
'PK_READING',arguments.colArray[qRowIndex]["PK_READING"],
qRowIndex);
QuerySetCell(tmpqry,
'ALARM_STATUS',arguments.colArray[qRowIndex]["ALARM_STATUS"],
qRowIndex);
QuerySetCell(tmpqry, 'DURATION',
arguments.colArray[qRowIndex]["DURATION"], qRowIndex);
QuerySetCell(tmpqry,
'DESCRIPTION',arguments.colArray[qRowIndex]["DESCRIPTION"],
qRowIndex);
</cfscript>
</cfloop>
<cfquery name="qry" dbtype="query" >
SELECT *
FROM tmpqry
ORDER BY #arguments.colSort# ASC
</cfquery>
<cfreturn qry >
</cffunction>
Rajesh
SCMS
India -
How to handle Coldfusion SOAP Web Service Errors
Hi,
I have just created simple wsdl example:
My Component:
<cfcomponent displayname="mytest">
<cffunction name="service_login_authentication" access="remote" output="true" returntype="any" hint="Returns login">
<cfargument name="login" type="string" required="yes">
<cfargument name="password" type="string" required="yes">
<cfif #arguments.login# eq "abcdef" and #arguments.password# eq "123456">
<cfxml variable="soapRes">
<kps_response>
<message>OK</message>
<token>354dfdffsdf</token>
</kps_response>
</cfxml>
<cfelse>
<cfthrow type="MyException" message="INVALID LOGIN" errorcode="1000" />
</cfif>
<cfreturn soapRes >
</cffunction>
</cfcomponent>
Its generating wsdl and no problem with response but when generating any error like username and password does not match then it's generating fault code like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>coldfusion.xml.rpc.CFCInvocationException: [coldfusion.runtime.CustomException : INVALID LOGIN. ]</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">HOST_NAME</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
But I want customize Fault Code like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>1000</faultcode>
<faultstring>INVALID LOGIN</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Fault Code and Fault String should be customize and I don't want detail tag completely. In old ColdFusion version like ColdFusion 8 displaying detail tag with <ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/"> coldfusion.xml.rpc.CFCInvocationException: and so on.
Any suggestions on how to create customize faultcode and faultstring is very helpful.
Thanks!!But my component is not produces this fault code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<<faultcode>1000</faultcode>
<faultstring>INVALID LOGIN</faultstring>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
What is your ColdFusion Version as i have checked in ColdFusion 11 developer edition and ColdFusion 8 enterprise which is on window 2003 server.
Could you please check my below component, did i am doing something wrong.
<cfcomponent output="false">
<cffunction name="service_login_authentication" access="remote" output="true" returntype="any" hint="Returns login">
<cfargument name="login" type="string" required="yes">
<cfargument name="password" type="string" required="yes">
<cfset var isLoginValid = False>
<cftry>
<cfif #arguments.login# eq "1111" and #arguments.password# eq "1111">
<cfset isLoginValid = True>
</cfif>
<cfif isLoginValid>
<cfsavecontent variable="soapRes"><?xml version="1.0" encoding="UTF-8"?>
<kps_response>
<message>OK</message>
<token>354dfdffsdf</token>
</kps_response>
</cfsavecontent>
<cfelse>
<cfthrow type="MyException" message="INVALID LOGIN" errorcode="1000" />
</cfif>
<cfcatch type="MyException">
<cfsavecontent variable="soapRes">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<<cfoutput><faultcode>#cfcatch.errorCode#</faultcode>
<faultstring>#cfcatch.message#</faultstring></cfoutput>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>
</cfcatch>
</cftry>
<cfreturn soapRes >
</cffunction>
</cfcomponent>
If my component is okay then may be possible some setting in ColdFusion administrator. i have checked in SoapUI as well via getSoapResponse method. -
Deleting a Record in Database - Error Message
Hello.
I have made a database, where i can view, edit, add new
records and its all working fine. I am trying to also have a delete
feature on it. I have created the link for it to delete, and added
the commands but im getting an error message when i hit delete
saying :
"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
Element DEPART is undefined in QARTIST.
i have looked through my coldfusion pages over and over but i
cant see anything which is wrong and i cant figure out what line
there might be a mistake on! could someone inform me what this
error message is saying to me please?
Thanks very very very very much in advanceHello.
Thanks very much for the response!
I have searched more on the missing variable but still cant
work out whats wrong.
Not sure why its saying 'depart' specfically as that is the
3rd row in the table.
Not too sure on where to go frm here. Could i ask for a bit
more specific help?
I have 3 an index page which displays the 7 rows + a link to
edit any of the returned data :
<td>#qArtists.CurrentRow#</td>
<td>#qArtists.FirstName#</td>
<td>#qArtists.LastName#</td>
<td>#qArtists.Depart#</td>
<td>#qArtists.Hotel#</td>
<td>#qArtists.Board#</td>
<td>#qArtists.Price#</td>
<td><a
href="updateartist.cfm?artistid=#qArtists.ArtistID#">Edit</a></td>
Then i have a :
artist.cfc which i added the delete code to :
<cffunction name="deleteArtist" access="public"
returntype="void">
<cfargument name="artistid" type="numeric"
required="yes">
<cfquery datasource="#application.datasource#">
DELETE FROM artists
WHERE ArtistID = #arguments.artistid#
</cfquery>
</cffunction>
then i have a delete.cfm file
<cfif IsDefined("form.artistid")>
<cfinvoke
component="cf8essentials.cfc.Artist"
method="deleteArtist">
<cfinvokeargument name="artistid"
value="#form.artistid#"/>
</cfinvoke>
<cflocation url="/cf8essentials/artists/index.cfm"
addtoken="no">
</cfif>
<cfform>
<cfinput type="submit" name="submit" value="Delete">
<cfinput type="button" name="cancel" value="Cancel"
onclick="history.back()">
<cfinput type="hidden" name="artistid"
value="#url.artistid#">
</cfform>
really not sure what part im doing wrong as i have fllowed
two different tutorials which do it different and both of theirs
work but im not sure what ive done wrong. Could you advise further
has ive been pulling my hair out over this for the past couple of
days now! thanks very much in advance again! -
Error inserting a row into a table with identity column using cfgrid on change
I got an error on trying to insert a row into a table with identity column using cfgrid on change see below
also i would like to use cfstoreproc instead of cfquery but which argument i need to pass and how to use it usually i use stored procedure
update table (xxx,xxx,xxx)
values (uu,uuu,uu)
My component
<!--- Edit a Media Type --->
<cffunction name="cfn_MediaType_Update" access="remote">
<cfargument name="gridaction" type="string" required="yes">
<cfargument name="gridrow" type="struct" required="yes">
<cfargument name="gridchanged" type="struct" required="yes">
<!--- Local variables --->
<cfset var colname="">
<cfset var value="">
<!--- Process gridaction --->
<cfswitch expression="#ARGUMENTS.gridaction#">
<!--- Process updates --->
<cfcase value="U">
<!--- Get column name and value --->
<cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
<cfset value=ARGUMENTS.gridchanged[colname]>
<!--- Perform actual update --->
<cfquery datasource="#application.dsn#">
UPDATE SP.MediaType
SET #colname# = '#value#'
WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
</cfquery>
</cfcase>
<!--- Process deletes --->
<cfcase value="D">
<!--- Perform actual delete --->
<cfquery datasource="#application.dsn#">
update SP.MediaType
set Deleted=1
WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
</cfquery>
</cfcase>
<cfcase value="I">
<!--- Get column name and value --->
<cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
<cfset value=ARGUMENTS.gridchanged[colname]>
<!--- Perform actual update --->
<cfquery datasource="#application.dsn#">
insert into SP.MediaType (#colname#)
Values ('#value#')
</cfquery>
</cfcase>
</cfswitch>
</cffunction>
my table
mediatype:
mediatypeid primary key,identity
mediatypename
my code is
<cfform method="post" name="GridExampleForm">
<cfgrid format="html" name="grid_Tables2" pagesize="3" selectmode="edit" width="800px"
delete="yes"
insert="yes"
bind="cfc:sp3.testing.MediaType.cfn_MediaType_All
({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
onchange="cfc:sp3.testing.MediaType.cfn_MediaType_Update({cfgridaction},
{cfgridrow},
{cfgridchanged})">
<cfgridcolumn name="MediaTypeID" header="ID" display="no"/>
<cfgridcolumn name="MediaTypeName" header="Media Type" />
</cfgrid>
</cfform>
on insert I get the following error message ajax logging error message
http: Error invoking xxxxxxx/MediaType.cfc : Element '' is undefined in a CFML structure referenced as part of an expression.
{"gridaction":"I","gridrow":{"MEDIATYPEID":"","MEDIATYPENAME":"uuuuuu","CFGRIDROWINDEX":4} ,"gridchanged":{}}
ThanksIs this with the Travel database or another database?
If it's another database then make sure your columns
allow nulls. To check this in the Server Navigator, expand
your DataSource down to the column.
Select the column and view the Is Nullable property
in the Property Sheet
If still no luck, check out a tutorial, like Performing Inserts, ...
http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
John -
Hi,
My CFC component is defined as:
<cffunction name="updateNote" output="false" access="remote" returntype="void" >
<cfargument name="notedetails" required="true" type="string" >
<cfargument name="notename" required="true" type="string" />
<cfquery name="qupdateNote" datasource="notes_db">
UPDATE
notes
SET
notes.notedetails=<CFQUERYPARAM CFSQLTYPE="CF_SQL_VARCHAR" VALUE="#ARGUMENTS.notedetails#">,
WHERE
notename="<CFQUERYPARAM CFSQLTYPE="CF_SQL_VARCHAR" VALUE="#ARGUMENTS.notename#">"
</cfquery>
</cffunction>
In Flash builder when I test the operation I get this error:
"There was an error while invoking the operation. Check your server settings and try invoking the operation again.
Reason: Server error Unable to invoke CFC - Error Executing Database Query. Parameter index out of range (2 > number of parameters, which is 1)."
Im really quessing that this is something small but right now its causing me to pull my hair out of my head!! Argg. Tried a bunch of things but I know thik im stuck.
Help would be very very appreciated.
ThanksCreate test.cfm along these lines:
<cfset myObj = createObject("component", "dotted.path.to.cfc.file")>
<cfset myResult = myObj.myMethod(arg=value1, etc)>
<cfdump var="#myResult#">
Or, really, you could just browse to this:
http://your.domain/path/to/your.cfc?method=yourMethod&arg1=value1 [etc]
Although I dunno which of those two approachs will give you a better error message (indeed, it might be the same).
Try both.
Adam -
401 Unauthorized error when calling a webservice
Have ColdFusion 11 installed, I have created a hello web service and I am trying to call it. Each time I try to call the web service I get an error 401 Unauthorized. I am not sure if I need to configure something more on the ColdFusion server, IIS or something else.
<cfcomponent displayname="Hello">
<cffunction name="helloWorld" returntype="string" access="remote">
<cfreturn "Hello World!">
</cffunction>
</cfcomponent>
<cfinvoke
webservice="http://MyServer/Hello.cfc?wsdl"
method="helloWorld"
returnvariable="ws" refreshwsdl="yes">
</cfinvoke>
<cfdump var="#ws#">It appears that you have inadvertently enforced HTTP authentication. If so, you will have to include the attributes, username="your_username" and password="your_password" in the cfinvoke tag.
-
Validation error for tag cfloop
Hi All,
Complete newbie to CF here. I've inherited (or bought) an online business which has its site written in CF. I haven't done this sort of stuff before but do work SQL for a living and object oriented stuff plus have done a bit of html and php so CF isn't mind blowing to me (in its simple form).
I've downloaded my site on to my computer to run a local copy that I can hack to pieces if needs be. For some reason, I have a few problems with the site running locally. The first error I'm getting is a Attribute validation error for tag cfloop.
Basically, index.cfm has this bit of code in it:
<cfinvoke component="#datasets#" method="storedProcedure" returnvariable="getFeaturedWineries_qry">
<cfinvokeargument name="storedProcedure" value="usp_GetFeaturedWineries">
</cfinvoke>
Ok, easy enough. Anyway, there's a call down the page to:
<cfinclude template = "#REQUEST.CFMPath#includes/displayFeaturedWineries.cfm">
Within displayFeaturedWineries.cfm is the code that calls the stored proc invoked above:
<cfloop query="getFeaturedWineries_qry" startrow="1" endrow="2">
Bam, that's where the error occurs. "The value of the attribute query, which is currently getFeaturedWineries_qry, is invalid.
What??? The stored proc exists and it only returns two records (which begs me to wonder why you would have startrow and endrow but anyway, it doesn't work with or without it).
The other interesting thing is that this works on production, NO PROBLEM!!! WTF? How can it work on production but not locally.
The only thing I'm starting to think is:
a) I've missed a setting somewhere in CF or
b) I'm running Apache as compared to IIS or
c) I'm running SQL 2008 and CF 9 which will no doubt be different to the production host server.
Should B or C be causing THAT type of problem??
Thanks,
MattI'm not sure what code apart from the above is going to show you what you could possibly need to solve this, but here goes. The following is only snippets of the code, but they are the relavant snippets. Other stored procs work. The cfdump for getFeaturedWineries_qry shows 'usp_getFeaturedWineries'. I know its there because I've been unable to run "EXEC usp_getFeaturedWineries" after copying it straight out of the code. As previously stated, there are other stored procs which are running fine.
datasets.cfc
<cffunction name="storedProcedure">
<cfargument name="storedProcedure" required="Yes" type="string">
<cfstoredproc procedure = "#ARGUMENTS.storedProcedure#"
datasource = "#REQUEST.DSN_NAME#"
username = "#REQUEST.DSN_USER#"
password = "#REQUEST.DSN_PASS#"
returncode = "Yes">
<cfprocresult name="storedProcedure" resultset="1">
</cfstoredproc>
<cfreturn storedProcedure>
</cffunction>
application.cfm
<!--- DATA SOURCE VARIABLES --->
<cfset DSN_NAME = "boutiqueWineriesTest">
<cfset DSN_USER = "coldfusion">
<cfset DSN_PASS = "coldfusion">
index.cfm
<cfobject component="#COMP_REF#.datasets" name="datasets">
<cfinvoke component="#datasets#" method="storedProcedure" returnvariable="getFeaturedWineries_qry">
<cfinvokeargument name="storedProcedure" value="usp_getFeaturedWineries">
</cfinvoke>
<cfinclude template = "#REQUEST.CFMPath#includes/displayFeaturedWineries.cfm">
displayFeaturedWineries.cfm
<cfloop query="getFeaturedWineries_qry" startrow="1" endrow="2">
Attribute validation error for tag cfloop.
The value of the attribute query, which is currently getFeaturedWineries_qry, is invalid. The error occurred in C:\apps\iishome\includes\displayFeaturedWineries.cfm: line 33
Called from C:\apps\iishome\index.cfm: line 399
Called from C:\apps\iishome\index.cfm: line 79
Called from C:\apps\iishome\index.cfm: line 1
31 : <tr>
32 : <td width="626" colspan="3" class="productCenter_bg2">
33 : <cfloop query="getFeaturedWineries_qry" startrow="1" endrow="2">
34 : <div class="productCennews">
35 : <table border="0" cellspacing="0" cellpadding="0"> -
We have a CFC page that was working fine before moving to CF9 from CF8. Any ideas on why it is no longer working? It is not processing at all now - just giving us this error.
<cfcomponent displayname="Checks For Email Address" output="true" hint="Checks for an Existing Email">
<cffunction access="remote" name="CheckInData" returntype="boolean" description="Checks Email and Returns True if Email Address Exists" hint="Checks Email and Returns True if Email Address Exists">
<cfargument name="Email_Check" type="string" required="true"/>
<cfquery name="data" datasource="datasource" dbtype="OLEDB">
SELECT
Email
FROM
EmailTable
WHERE
Email=<cfqueryparam value="#Trim(arguments.Email_Check)#" cfsqltype="cf_sql_varchar" />
AND
Company_ID='#company_ID#'
</cfquery>
<cfif data.RecordCount EQ 0>
<cfreturn false>
<cfelse>
<cfreturn true>
</cfif>
</cffunction>@cover,
I see two things you might change, but I don't know if they will solve the problem. First, you don't need the "dbtype" attribute anymore with CFQuery, unless it's dbtype="query". Second, it's possible you have a race condition on your query results variable ("data"). You might add a line right below the CFArgument tag:
<cfset var data = "">
This will make the "data" variable local to the function.
Other than that, I can't see anything obvious. I'm not at all versed in WDDX, so maybe someone else will have some better ideas.
-Carl V.
Maybe you are looking for
-
How do i transfer my itunes library from one macbook to another?
hi,how do i transfer my itunes library from one macbook to another?
-
Ipod all of a sudden not communicating with Bose sound system
I am having trouble with my ipod communicating with my Bose music system. First off please let me mention that I have tried all troubleshooting procedures for both the ipod and the Bose system and nothing has help. I do believe that it is a malfuncti
-
How do I unlock the sim card if my iPhone 5 has not been activated?
I gave my iPhone 5 to my mom, so I restored it first (by going through Find my iPhone and deleting the phone and restoring it), and now my mom got a new nano sim card. When I enter it into the phone, it says "Your iPhone could not be activated becaus
-
Unable to view photos in iPhoto, although all pictures are still accessible via Finder?
Last week, I was trying to import some pictures from a USB flash drive. During the import, I got an error that some of the pictures were corrupt and iPhoto '08 7.1.5 stopped the process. At that time, iPhoto still showed all my events and pictures co
-
Vendor Address is not updating in ADRC table by LSMW IDOC method
Hi, I'm updating Vendor address data by LSMW IDoc method for this i'm using ADRMAS as msg type and ADRMAS02 as Idoc type. In partner profiles Process code given as BAPI for this. i maintained entry in TSADOBJ table LFA1 as OBJTYPE,1 as ADDR TYPE,0001