Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:33:49+00:00 2026-05-14T07:33:49+00:00

I have a database table that is a dictionary of defined terms — key,

  • 0

I have a database table that is a dictionary of defined terms — key, value. I want to load the dictionary in the application scope from the database, and keep it there for performance (it doesn’t change).

I gather this is probably some sort of “struct,” but I’m extremely new to ColdFusion (helping out another team).

Then, I’d like to do some simple string replacement on some strings being output to the browser, looping through the defined terms and replacing the terms with some HTML to define the terms (a hover or a link, details to be worked out later, not important).

This is the code currently in the application.cfc file:

<cffunction name="onApplicationStart">
<cfquery name="qryDefinedTerms" datasource="mydsn">
       SELECT term, definition FROM definedterms
    </cfquery>
<cfset application.definedterms = Array(1)>
<cfloop query="qryDefinedTerms">
    <cfset myHash = structNew()>
    <cfset myHash.put("term", qryDefinedTerms.term)>
    <cfset myHash.put("definition", qryDefinedTerms.definition)>
    <cfset ArrayAppend(application.definedterms, myHash)>
</cfloop>
</cffunction>

The calling page attempts to use it as follows:

function ReplaceDefinitions(inputstring) {
    for (thisdef = 1 ;
        thisdef LTE ArrayLen(application.definedterms);
        thisdef = (thisdef+1)) {
        inputstring = Replace(inputstring, 
           application.definedterms(thisdef).term, 
           application.definedterms(thisdef).definition, "ALL");
    }
    return inputstring;
}

When I call the function, I get back: “Element DEFINEDTERMS is undefined in APPLICATION”.

Edit: forcing a call to OnApplicationStart() worked, apparently Cold Fusion’s application.cfc isn’t like ASP.NET’s web.config, changing it doesn’t reset the application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:33:49+00:00Added an answer on May 14, 2026 at 7:33 am

    There are a lot of separate questions you’ve asked but I’ll have a go at answering them! You also haven’t said what version of ColdFusion you are using, so I’m going to answer with code that will work in ColdFusion 8 and higher.

    ColdFusion uses a special file called Application.cfc that you put in the route of your web application (similar to Global.asax in ASP.Net). It has a method in in called onApplicationStart that is only executed when the application starts (so not on each request). This is a great place to put any constants. Here is a simple example which sets a struct (like a map in other languages) using the {} syntax:

    Application.cfc

    <cfcomponent>
      <cffunction name="onApplicationStart">
        <!--- set global constants here --->
        <cfset application.foo = { a=1, b=2, c="my string" }>
      </cffunction>
    </cfcomponent>

    If you want to get the data from a database, here is a simple way to do it (there are lots of other ways that are probably better but this should get you started!)

    <cfcomponent>
      <cffunction name="onApplicationStart">
        <!--- set global constants here --->
        <cfset application.datasource = "mydsn">
    
        <cfquery name="qryConstants" datasource="#application.datasource#">
          select key, value
          from tblConstants
        </cfquery>
    
        <cfset application.constants = {}>
        <cfloop query="qryConstants">
          <cfset application.constants[ qryConstants.key ] = qryConstants.value>
        </cfloop>
      </cffunction>
    
    </cfcomponent>

    As for replacing values in a string then you can do something like this:

    somescript.cfm

    <cfsavecontent variable="somestring">
    Hello, ${key1} how are you? My name is ${key2} 
    </cfsavecontent>
    
    <!--- replace the ${key1} and ${key2} tokens --->
    <cfloop collection="#application.constants#" item="token">
      <cfset somestring = ReplaceNoCase( somestring, "${#token#}", application.constants[ token ], "all" )>
    </cfloop>
    
    <!--- show the string with tokens replaced --->
    <cfoutput>#somestring#</cfoutput>

    As I said there are lots of ways to solve your question, however hopefully you’ll find this a good starting point (although I haven’t tested it!).

    Good luck and welcome to ColdFusion!

    • John
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 389k
  • Answers 389k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer think i've worked out a decent solution to this, so… May 15, 2026 at 12:47 am
  • Editorial Team
    Editorial Team added an answer You can take a look at dijit.form.MultiSelect. May 15, 2026 at 12:47 am
  • Editorial Team
    Editorial Team added an answer It turns out Enlive does escape HTML by default if… May 15, 2026 at 12:47 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.