Solved

How do I cfset a variable in cfquery

Posted on 2011-09-09
9
316 Views
Last Modified: 2012-05-12
How do I cfset a variable in cfquery so the values will be available in a pull down in a cfgrid

<cfquery name="Get_modality" datasource="xxx">
            SELECT    TDA_UIC, TYPE, ORG_ID_EM
                  FROM      MRE_TARA_MODALITIES
</cfquery>

    <cfset ModalityType = "TYPE">

<cfform>  
<cfgrid>
<cfgridcolumn name="MODALITY"  header="Modality(E)"  width="90" values="#ModalityType#"/>    
</cfgrid>
</cfform>  
0
Comment
Question by:Nigel-SA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 36515862
Like this:
<cfquery name="Get_modality" datasource="xxx">
            SELECT    TDA_UIC, [TYPE] as ModalityType, ORG_ID_EM
                  FROM      MRE_TARA_MODALITIES
</cfquery>

<cfform>   
<cfgrid name="myGrid" query="Get_modality">
  <cfgridcolumn name="ModalityType"  header="Modality(E)"  width="90" />     
</cfgrid>
</cfform>

Open in new window

0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 36518330
for using the any Cfset variable you set you had to specify a query
0
 

Author Comment

by:Nigel-SA
ID: 36522075
Sorry my fault, I wasn't detailed enough.  Basically I have a main cfgrid query called getICS but wanting to have a pull down within the cfgrid extracting the variable from from another query (Get_modality), so I can insert the value from "Get_modality.Type" into "MODALITY"


<cfquery name="Get_modality" datasource="xxx">
            SELECT    TDA_UIC, TYPE, ORG_ID_EM
            FROM      MRE_TARA_MODALITIES
</cfquery>
   
    <cfset ModalityType = "TYPE">


<cfquery name="getICS" datasource="xxx">
    SELECT   *.*
    FROM MRE_TARA_LIST
</cfquery>

<cfset args = structNew()>
<cfset args.name = "ICS_Grid">
<cfset args.format = "html">
<cfset args.query = "getICS">
<cfset args.stripeRows = true>
<cfset args.selectmode = "edit">
<cfset args.onchange = "cfc:TARA_LIST.editData({cfgridaction},{cfgridrow},{cfgridchanged})">
   
     <cfform>
     
        <cfgrid attributeCollection="#args#">
<cfgridcolumn name="TARA_ID" header="MOD ID" display="no" width="40"/>
<cfgridcolumn name="ORG_ID_EM"  display="no" header="DODAAC"  width="80"/>
<cfgridcolumn name="TDA_UIC"  header="TDA UIC"  display="no" width="80"/>
<cfgridcolumn name="MODALITY"  header="Modality(E)"  width="90" values="#ModalityType#"/>        
<cfgridcolumn name="LOCATION"  header="Location(E)"  width="90"/>
        </cfgrid>
                         
     </cfform>
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 63

Expert Comment

by:Zvonko
ID: 36527321
You set the ModalityType like this:
<cfquery name="Get_modality" datasource="xxx">
            SELECT    TDA_UIC, TYPE, ORG_ID_EM
            FROM      MRE_TARA_MODALITIES
</cfquery>
<cfset ModalityType=ArrayNew(1) >
<cfloop query="Get_modality" >   
    <cfset ArrayAppend(ModalityType,TYPE) >
</cfloop>

Open in new window

0
 

Author Comment

by:Nigel-SA
ID: 36528734
Thanks Zvonko, that works - the ModalityType values are loading however I receive the "Complex object types cannot be converted to simple values." error on the line in the cfgrid

  <cfgrid attributeCollection="#args#">
<cfgridcolumn name="MODALITY"  header="Modality(E)"  width="90" values="#ModalityType#"/>  
    </cfgrid>

Full error description:
Complex object types cannot be converted to simple values.  
The expression has requested a variable or an intermediate expression result as a simple value, however, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you are trying to use a complex value as a simple one. For example, you might be trying to use a query variable in a cfif tag

Thanks for your help!!
 
0
 

Accepted Solution

by:
Nigel-SA earned 0 total points
ID: 36529209
Zvonko:  I replaced:

<cfset ModalityType=ArrayNew(1) >
<cfloop query="Get_modality" >   
    <cfset ArrayAppend(ModalityType,TYPE) >
</cfloop>

with the following and it worked, (cfgrid remains the same)
<cfset ModalityType = ValueList(Get_modality.TYPE)>



0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36534007
Fine.
0
 

Author Closing Comment

by:Nigel-SA
ID: 37023024
Accidentally found the correct answer
0
 

Author Comment

by:Nigel-SA
ID: 36999123
Please delete question - I found the solution
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question