[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Dynamic variables with Coldfusion

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##">
1 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])>

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now