Dynamic variables with Coldfusion

Posted on 2007-10-15
Last Modified: 2013-12-24
I've created a dropdown that gets populated dynamically. For this drop down I need variables in Attributes scope and in Session scope. This is a search page. when submitted I write Attributes value to session variables to maintain search criteria. This has been working just fine until now when the client is asking for dynamic dropdowns. Could someone please tell me how this can be done. Below is code, I have a problem when I'm trying to write Attributes value to session variable.

<cfquery name="qry_get_dropdown_variable" datasource="#Request.dS#">
Select Distinct Field_Name from #request.client#_BASIC_SEARCH_FIELDS

<cfloop query="qry_get_dropdown_variable">
  <cfparam name="attributes.#Field_Name#" default="">

<cfdump var="#attributes#">

<cflock timeout="20" type="EXCLUSIVE" scope="Session">
  <cfloop query="qry_get_dropdown_variable">
 <!--- I have problems below this line of how to check if the lenth is greater than 0 means this field was submitted by the form --->
    <cfif len("attributes.#Field_Name#")>
      <cfset Session.#Field_Name# = "#attributes.#Field_Name##">
Question by:aliasim99
    1 Comment
    LVL 51

    Accepted Solution

    IIRC attributes is a structure.  You can test for the existence of a field using StructKeyExists

      <cfif structKeyExists(attributes, fieldName) >

    You get the value using array notation

      <cfif len(attributes[fieldName])>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Network it in WD Red

    There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

    Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: :…
    The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now