Solved

How do I cfset a variable in cfquery

Posted on 2011-09-09
9
310 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
Comment Utility
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:myselfrandhawa
Comment Utility
for using the any Cfset variable you set you had to specify a query
0
 

Author Comment

by:Nigel-SA
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Nigel-SA
Comment Utility
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
Comment Utility
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
Comment Utility
Fine.
0
 

Author Closing Comment

by:Nigel-SA
Comment Utility
Accidentally found the correct answer
0
 

Author Comment

by:Nigel-SA
Comment Utility
Please delete question - I found the solution
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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