Solved

How do I cfset a variable in cfquery

Posted on 2011-09-09
9
318 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
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

628 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