Solved

How do I cfset a variable in cfquery

Posted on 2011-09-09
9
312 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
  • 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 15

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
 
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
3 Use Cases for Connected Systems

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

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Date Query 28 44
How can I exclude some wording in a like statement? 39 66
SQL Error in WHERE Clause 5 41
Getting same value for every field in SQL 2 29
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now