troubleshooting Question

How do I return a variable from a CFC function and then know what is returned in a CFM form?

Avatar of dawes4000
dawes4000Flag for United States of America asked on
Web Servers
4 Comments1 Solution235 ViewsLast Modified:
I have a form that invokes a function in a CFC, in the this CFC function I query for a record, if the record exists I want a return variable "true" sent to my CFM form, and then make decisions based on what was returned. Here is some code below:

<cfif #form.btnSubmitUser# EQ "Submit User">
   <cfif #form.dealerID# NEQ "-1">
      <cfinvoke component="ccCompany" method="AddUser"
      CompanyID="#form.dealerID#"
      UserID="#form.UserID#"
      Fname="#form.fName#"
      Lname="#form.lName#" returnvariable="ValidID">
       <cfif returnvariable.Valid EQ "true">
          User has been added
        <cfelseif returnvariable.Valid EQ "false">
          UserID is in use
        </cfif>
   <cfelse>
      <cfoutput>
        <table class="fontRegular">
           <tr>
      <td>
      User was not submitted.<br>
      When adding a User make sure you Select a Dealer.
      </td>
           </tr>
       </table>
      </cfoutput>
   </cfif>                                          
</cfif>

<!--- BELOW IS THE FUNCTION -->
<cffunction name="AddUser" access="public">
      <cfargument name="UserID" required="yes">
      <cfargument name="CompanyID" required="yes">
      <cfargument name="Fname" required="yes">
      <cfargument name="Lname" required="yes">
      <cfquery name="qryVerifyID" datasource="#session.connString#">
            SELECT UserID FROM tblUser WHERE UserID = '#arguments.UserID#'
      </cfquery>
      <cfif qryVerifyID.recordcount EQ 0>
            <!--- ADD USER and PWD --->
            <cfquery name="qryAddUser" datasource="#session.connString#">
                  Insert into tblUser (UserID, fName, lName, companyID, rights) VALUES ('#arguments.UserID#', '#arguments.fName#', '#arguments.lName#', '#arguments.CompanyID#', '1')
            </cfquery>
            <cfquery name="qryAddPWD" datasource="#session.connString#">
                  Insert into tblPWD (UserID, PWD) VALUES ('#arguments.UserID#','#arguments.UserID#')
            </cfquery>
            <cfreturn true>
      <cfelse>
            <!--- UserID is taken --->
            <cfreturn false>
      </cfif>
</cffunction>
ASKER CERTIFIED SOLUTION
Netminder

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros