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#,#G RAPH#,#STR ING_TAG#,# VIS_ART_EN G#
I want to use m_list in a CFFile tag like this:
<cffile action="append" file="/u01/web/ibis/papers /files/mjt est.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
#LH_AS_100#,#LH_AS_50#,#RH
I want to use m_list in a CFFile tag like this:
<cffile action="append" file="/u01/web/ibis/papers
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
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>
<cfset m_listString = "">
<cfloop list="var1,var2,var3,var4"
<cfset m_listString = listAppend(m_listString, variables[x])>
</cfloop>
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#,#G RAPH#,#STR ING_TAG#,# VIS_ART_EN G#
Whereas it should be returning:
3,4,5,6,7
for example.
It's returning:
#LH_AS_100#,#LH_AS_50#,#RH
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...
mjacobs2929,
Can you post the code used to generate/populate the 'm_list' variable?
Can you post the code used to generate/populate the 'm_list' variable?
ASKER
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#,#G RAPH#,#STR ING_TAG#,# VIS_ART_EN G#
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_n ame#")>
But doing a similar trick with a list of vars is proving more difficult.
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
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_n
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#,#G RAPH#,#STR ING_TAG#,# VIS_ART_EN G#
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.columnLis t#" index="col">
<cfset m_list = listAppend(m_list, yourQuery[col][rowNumber]) >
</cfloop>
> The example here is an actual 'cut n paste' of the resulting m_list:
> #LH_AS_100#,#LH_AS_50#,#RH
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.columnLis
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.