Hi, in my cfc, i have insert query into the table. I want it to return the message and send it back to cfm page but don't know how, can you please help? Thanks KT
<cffunction name="add" returntype="query">
<cfargument name="form" required="yes" type="struct">
<cfquery name="insertMessage" datasource="#request.dbsource#" result="returnMessageID">
INSERT INTO admin_Message
<cfqueryparam value="#trim(arguments.form.title)#" cfsqltype="cf_sql_varchar" maxlength="255" />,
<cfqueryparam value="#trim(arguments.form.description)#" cfsqltype="cf_sql_longvarchar" />,
<!--- if insert fails --->
<cfobject type="component" name="request.outages" component="cfcs.outage">
<cfset variables.add = request.outages.add(form)>
i want to diplay message here after the inserted from cfc
This is kind of a rookie approach we all do at some point, but it's good to get away from as soon as you can.
Java/CF already provides a mechanism to bubble back success/fail situations to the calling code: it's called an exception. If your code is successful, it will return to the mainline code when it's done. If it's unsuccessful, it'll raise an exception. It's then up to your calling code to decide what to do with that. Your method should simply be "add the record", not "add the record and return a message as to the operation's success". As soon as you need to use the word "and" in the description of a method's functionality, you're probably trying to do too much with the method.
A sensible return value from an add() method might be to return the ID of the object just added. But returning success/fail will seldom be a good approach to handling success/failure situations. Use the mechanism provided: the exception.
Europe, Middle East and Africa