Skip to main content
Known Participant
April 23, 2011
Question

understanding application variables

  • April 23, 2011
  • 2 replies
  • 533 views

I'm getting started with Coldfusion and making some tests with application variables.

I am not understanding the way coldfusion update values of application variables.

For example

<cfparam name="application.userList" type="string" default=""> <cfif listLen(application.userList) eq 0> <cfquery name="getUsers"> SELECT * FROM members </cfquery> <cfset application.userList = valueList(getUsers.username)> </cfif> <cfoutput>#application.userList#</cfoutput>

ok I get the following output

username1, username2,username3...

Then I added a record into database and I run the same above code.

Does Coldfusion allow to update the value of an application variable at runtime ?

Why application.userList does not update ?

Any suggestion is much appreciated !

This topic has been closed for replies.

2 replies

Inspiring
April 23, 2011

Well... after the first request, in which you set application.userlist to be [whatever]... will listlen(application.userList) equal zero (ie: your IF condition)?  No.

So once you set your application.userlist to [something], your code specifically prevents it being updated again.

Re-think your logic.

--

Adam

ilssac
Inspiring
April 23, 2011

Filippo Lughi wrote:

Then I added a record into database and I run the same above code.

Does Coldfusion allow to update the value of an application variable at runtime ?

Why application.userList does not update ?

Yes application variables are updateable at runtime.  Your code is doing just that.  The only thing special about application variables is that they are global to ALL cfml templates running under the same application name on the same ColdFusion server.

Why your application.userList does not update, would be a question about your database.  Because there is nothing in your CFML code that would prevent it.  The first two database questions to ask are:

1) Are you updating the same database that ColdFusion is connected to and from which it is reading its data?

2) Are you COMMITTING the data update with whatever method you might be using to insert the new records?

Known Participant
April 23, 2011

1) yes

2) yes

ops I forgot to take off the if statement