Skip to main content
Participant
October 2, 2009
Question

Get ID element from CFC

  • October 2, 2009
  • 1 reply
  • 857 views

Hello -

I'm attempting to use my first CFC in conjunction with cfinput and autosuggest.  As is currently, everything works as far as the autosuggestion goes.  My simple  form is this:

<cfform action="#cgi.SCRIPT_NAME#">

     Client: <cfinput type="text"

                         name="client"

                         autosuggest="cfc:client.lookupClient({cfautosuggestvalue})" size="90">

<br />

  <input type="submit" value="Save">

</cfform>

My CFC is:

<cfcomponent output="false">

          <cfset THIS.dsn="myDSN">

     <!--- Lookup used for auto suggest --->    

     <cffunction name="lookupClient" access="remote" returntype="array">

     <cfargument name="search" type="any" required="false" default="">

     <!--- Define variables --->

     <cfset var data="">

     <cfset var result=ArrayNew(1)>

     <!--- Do search --->

     <cfquery datasource="#THIS.dsn#" name="data">

     SELECT clientID,firstName,lastName,email,organization  FROM client

     WHERE UCase(lastname) LIKE Ucase('#ARGUMENTS.search#%')

     ORDER by lastname, firstname

</cfquery>

<!--- Build result array --->

<cfloop query="data">

     <cfset name = '#lastname#, #firstname# (#email# - #organization#),  #clientID#'>  

     <cfset ArrayAppend(result, #name#)>

</cfloop>

<!--- And return it --->

<cfreturn result>  

   </cffunction>   

  </cfcomponent>

The data returns to the textbox formatted how I want it to be; however, when the  form submits, I only want the ID to post to the record.  How may I obtain the ID  from the CFC to use it in a hidden field of the form so the associated ID of the  client posts to the database record?

Thank you

This topic has been closed for replies.

1 reply

Inspiring
October 2, 2009

Your question is not clear.  What ID are you trying to obtain?

A__ParkerAuthor
Participant
October 2, 2009

I apologize.  The textbox is populated with client information (lastname, firstname, email, organization) for staff to select the appropriate client.  I am trying to obtain the ID of the selected client so that when the form posts to the database, the clientID is saved to the table.

The way it is set up now, the staff are pleased as they see the relevant client information.  Staff do not care about the clientID.  On the other hand, I need the clientID so the record can be created in the database.  I don't care about the lastname, firstname, email or organization.

Thank you.

Inspiring
October 2, 2009

The query in your cfc selects the client id which eventually gets returned to the calling template.  Can we now say so far so good?  At what point do your problems begin.