• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cf9 cfselect bind

New Here ,
May 16, 2014 May 16, 2014

Copy link to clipboard

Copied

I have multiple dropdown lists on a form that are interdependent on each other. So, I'm using cfselects with binding based on selection of the previous drop down.

Here's the scenario:

Each 'sales representative' is assigned a number of clients. In turn, the clients are assigned a designated customer service rep.

I have a form that is using a cfselect to bind the clients displayed in the client list based on which sales representative is selected.

Once the 'client' is selected, I would like the next drop down list to populate with all customer service reps but have the rep that is actually assigned to the client be the default selected item in the drop down (e.g., selected="selected"). I need all service reps listed because there are instances that a case will be assigned to a different service rep than the default.

I have scoured the web and reviewed many examples but am still at a loss.

In my research found something similar to the code I'm using in the cfc (below) to pull the a list of all service reps and compare to see if the rep id is the client's designated rep.

<cfset result[i+1][3]=true> is being populated correctly, however this does not carry over to my cfselect to indicate the item selected.

Is there a different way I need to go about this?

Please ask if I'm not being clear in what I need this to do.

THANKS in advance for any assistance!

Code snippet:

<cffunction name="getSvcReps" access="remote" returnType="array">

  <cfargument name="clientId" type="any" required="yes">

  <cfargument name="dsn" type="any" required="yes">

  <!---defines variables--->

  <cfset var data="">

  <cfset var result=ArrayNew(2)>

  <cfset var i=0>

  <cfif not len(arguments.clientId)>

  <cfset result[1][1]="">

  <cfset result[1][2]="Please select a Client--->">

  <cfreturn result>

  <cfelse>

  <cfquery datasource="#arguments.dsn#" name="svcReps">

  SELECT

  service_rep_id

  ,CONCAT(first," ",last) as svc_rep_name

  FROM

  svc_reps

  </cfquery>

  <cfquery datasource="#arguments.dsn#" name="defaultSvcRep">

  SELECT

  rep_id

  FROM

  client_reps

  WERE

  client_id ='#arguments.clientId#'

  and rep_type="svc"

  </cfquery>

  <!---convert results to array--->

  <cfset result[1][1]="">

  <cfset result[1][2]="Select a Service Representative--->">

  <cfset result[1][3]="">

  <cfloop index="i" from = "1" to="#svcReps.recordCount#">

  <cfset result[i+1][1]=svcReps.service_rep_id>

  <cfset result[i+1][2]=svcReps.svc_rep_name>

  <cfif svcReps.service_rep_id EQ defaultSvcRep.rep_id>

  <cfset result[i+1][3]=true>

  <cfelse>

  <cfset result[i+1][3]="">

  </cfif>

  </cfloop>

  <cfreturn result>

  </cfif>

</cffunction>

TOPICS
Advanced techniques

Views

263

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 17, 2014 May 17, 2014

Copy link to clipboard

Copied

LATEST

Adobe's documentation on cfselect contains a useful example. I have modified it to suit your needs.

Just copy the following 3 files into the same directory, and run testPage.cfm.

testPage.cfm

<cfform name="mycfform">

    <cfselect name="state" bind="cfc:bindFcns.getstates()" bindonload="true" >

    </cfselect>

    <cfselect name="city" bind="cfc:bindFcns.getcities({state})">

    </cfselect>

</cfform>

bindFcns.cfc

<cffunction name="getXmlData" output="false" returntype="xml" access="private">
    <cfset var xmlData = "">
    <cffile action="read" file="#expandpath('.')#\states.xml" variable="xmlData">
    <cfset xmlData = XmlParse(xmlData)>
    <cfreturn xmlData>
</cffunction>

<cffunction name="getStates" access="remote" returntype="array">
    <cfset var state = arraynew(2)>
    <cfset var xmlData = getXmlData()>
    <cfset var numStates = 0>

    <cfset numStates = ArrayLen(xmlData.states.XmlChildren)>
   <cfset state[1][1] = "">
    <cfset state[1][2] = "== State ==">
    <cfloop from="1" to="#numStates#" index="j">
        <cfset state[j+1][1] = ltrim(xmlData.states.state.XmlAttributes.abr)>
        <cfset state[j+1][2] = ltrim(xmlData.states.state.name.xmlText)>
    </cfloop>
    <cfreturn state>
</cffunction>

<cffunction name="getCities" access="remote" returntype="array">
    <cfargument name="state" required="yes">
    <cfset var city = arraynew(2)>
    <cfset var xmlData = getXmlData()>
    <cfset var numStates = 0>
    <cfset var numCities = 0>

    <cftry>
        <cfset numStates = ArrayLen(xmlData.states.XmlChildren)>
   <cfset city[1][1] = "">
        <cfset city[1][2] = "== City ==">
        <cfloop from="1" to="#numStates#" index="j">
            <cfif xmlData.states.state.XmlAttributes.abr eq state>
                <cfset numCities = ArrayLen(xmlData.states.state.cities.XmlChildren)>
                <cfloop from="1" to="#numCities#" index="k">
                    <cfset city[k+1][1] =ltrim(xmlData.states.state.cities.city.XmlAttributes.name)>
                    <cfset city[k+1][2] = ltrim(xmlData.states.state.cities.city.XmlAttributes.name)>
                </cfloop>
                <cfbreak>
            </cfif>
        </cfloop>
    <cfcatch type="any">
        <cfdump var="#cfcatch#">
    </cfcatch>
    </cftry>
    <cfreturn city>
</cffunction>

</cfcomponent>

states.xml

<states>

    <state abr="NJ">

        <name>New Jersey</name>

        <cities>

            <city name="Edison" />

            <city name="Rahway" />

            <city name="Atlantic City" />

            <city name="Hoboken" />

            <city name="Jersey City" />

            <city name="Newark" />

            <city name="Trenton" />

            <city name="Union City" />

        </cities>

    </state>

    <state abr="CA">

        <name>California</name>

        <cities>

            <city name="Anaheim" />

            <city name="Beverly Hills" />

            <city name="Elk Grove" />

            <city name="Fairfield" />

            <city name="Fremont" />

            <city name="Indian Wells" />

            <city name="Long Beach" />

        </cities>

    </state>

    <state abr="ME">

        <name>Maine</name>

        <cities>

            <city name="Augusta" />

        </cities>

    </state>

    <state abr="MA">

        <name>Massachusetts</name>

        <cities>

            <city name="Boston" />

            <city name="Cambridge" />       

        </cities>

    </state>

</states>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation