Mia
Mia

Reputation: 1

ColdFusion CFC returning record count

Question: I have a CFM calling my CFC on the cfform action line:

In my CFC, I have output="false". I am needing the record count sent back to my CFM. When I run my CFM and enter the form info my queries are running successfully, but it is not coming back to my CFM so I can display the proper messages. I just get the CFC page with my record count. Any suggestions? Thanks!

Upvotes: 0

Views: 1097

Answers (2)

mia
mia

Reputation: 1

I changed the cfform line to this: ....rest of my form

then added these lines to see if the form was submitted and what action is:

<!--- create object for cfc --->

But now, my query is not running....

Upvotes: 0

Billy Cravens
Billy Cravens

Reputation: 1663

Since there's no code, making a few assumptions here about how you're doing things ....

Don't point to the CFC, point to a CFM page in your <cfform>. (If you omit the action, it'll point back to itself.. I like self-referencing form pages)

In your CFC, return the result struct from your query:

<cfquery datasource="#ds#" name="myQuery" result="myResult">
    INSERT INTO myTable .....
</cfquery>

Then either return that entire struct, or just myResult.recordCount:

<cfreturn myResult.recordCount>

Then in your CFM page, you'll access it like so (assuming you're using <cfscript>; similar if you're doing tag-based):

recordsAdded = createObject('component','myFolder.myCFC').insertMethod(form);

Upvotes: 3

Related Questions