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

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
0
mjacobs2929
Asked:
mjacobs2929
  • 3
  • 3
  • 2
  • +1
1 Solution
 
Russell2566Commented:
You are going to have to loop through the list to create your string value then insert that into the cffile output.
0
 
Russell2566Commented:
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>
0
 
mjacobs2929Author Commented:
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.


0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
Russell2566Commented:
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...
0
 
_agx_Commented:
mjacobs2929,

Can you post the code used to generate/populate the 'm_list' variable?
0
 
mjacobs2929Author Commented:
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.
0
 
_agx_Commented:
> 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>

0
 
_agx_Commented:
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 :)
0
 
Scott BennettCommented:
Try it 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(de(m_list))#"
      addnewline="yes">
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now