Link to home
Start Free TrialLog in
Avatar of mjacobs2929
mjacobs2929

asked on

Evaluate List of ColdFusion Variables

I have a list of ColdFusion variables in a variable called m_list, which looks like this:
#LH_AS_100#,#LH_AS_50#,#RH_AS_50#,#GRAPH#,#STRING_TAG#,#VIS_ART_ENG#

I want to use m_list in a CFFile tag like this:
<cffile action="append" file="/u01/web/ibis/papers/files/mjtest.csv"
        output="#month# #year# , #file_type# , #s_code# , #s_name# , #s_country# , #evaluate('m_list')#"
      addnewline="yes">

Of course, I want the returned values of the vars, but evaluate() is not working  - in other words, the literal var names are still being returned. I've tried several some variations here, but none have worked.  What am I missing?

Any help welcome.

Many thanks,
MJ
Avatar of Russell2566
Russell2566
Flag of United States of America image

You are going to have to loop through the list to create your string value then insert that into the cffile output.
I would also recomend doing something like the following instead doing a eval on each options.

<cfset m_listString = "">
<cfloop list="var1,var2,var3,var4" index="x">
    <cfset m_listString = listAppend(m_listString, variables[x])>
</cfloop>
Avatar of mjacobs2929
mjacobs2929

ASKER

Nope, the list is working fine in the cffile as it is. It's just not returning the actual variables.

It's returning:
#LH_AS_100#,#LH_AS_50#,#RH_AS_50#,#GRAPH#,#STRING_TAG#,#VIS_ART_ENG#

Whereas it should be returning:
3,4,5,6,7
for example.


When I evalute any variable with a comma in it, I get an error (as I should) because CF can't evaluate it... What ever your current result is, I would recomend using a different logic to step away from using the evaluate... Not looking over your shoulder it's hard to say but I'm guessing there are several other methods that will achieve getting the values you need into the appropriate list to output in the file before you get to the cffile...
Avatar of _agx_
mjacobs2929,

Can you post the code used to generate/populate the 'm_list' variable?
Not until tomorrow...
m_list is dynamic and must be able to change. The list is built up from the results of a query.

I'm using ListQualify() to add the #'s around each item in the list.
The example here is an actual 'cut n paste' of the resulting m_list:
#LH_AS_100#,#LH_AS_50#,#RH_AS_50#,#GRAPH#,#STRING_TAG#,#VIS_ART_ENG#

I wish to have Coldfusion recognise each listed variable as a variable. At the moment, they are treated as literals by CF.

I've used evaluate() in the past to build variables successfully, such as
<cfset pageBatch = evaluate("MaxRows_#query_name#")>
But doing a similar trick with a list of vars is proving more difficult.
> I'm using ListQualify() to add the #'s around each item in the list.
> The example here is an actual 'cut n paste' of the resulting m_list:
> #LH_AS_100#,#LH_AS_50#,#RH_AS_50#,#GRAPH#,#STRING_TAG#,#VIS_ART_ENG#

Well that might explain why its not working. Are those column names? If they are an easy way to retrieve the values dynamically is to use array notation

<cfset m_list = "">
<cfloop list="#yourQuery.columnList#" index="col">
    <cfset m_list = listAppend(m_list, yourQuery[col][rowNumber])>
</cfloop>

I understand that the m_list values are dynamic.  But it would still help to see the code.  I suspect it would show us where the problem is.  Without that, we're just guessing :)
ASKER CERTIFIED SOLUTION
Avatar of Scott Bennett
Scott Bennett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial