Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:00:08+00:00 2026-05-23T17:00:08+00:00

I am trying to write a custom tag that will iterate over a cfquery

  • 0

I am trying to write a custom tag that will iterate over a cfquery object in a special way. I found this page: http://www.zrinity.com/developers/mx/undocumentation/query.cfm outlining how to use the underlying java methods to navigate the result set, but it doesn’t seem to be working in CF9.

I can call .next(), .previous(), .first(), and .last() just fine, and each method updates query.currentRow, but referencing query.columnName always returns the value from the first row, not currentRow.

Example:

<cfquery name="testQuery" datasource="source">
  SELECT FooName FROM NumberedFoos
</cfquery>

<cfloop from="1" to="3" index="i">
  <cfoutput>#testQuery.currentRow# =&gt; #testQuery.fooName#</cfoutput><br />
  <cfset testQuery.next()>
</cfloop>

Produces:

1 => Foo 1
2 => Foo 1
3 => Foo 1

I know i could use something like testQuery.fooName[testQuery.currentRow], but that is pretty undesirable for the people I am making the custom tag for. Was the functionality described in the above link removed from CF9? If so is there an alternative?

EDIT

To expand on the why, the client wants a custom tag that allows them to “assert” certain things about a query. The client has a pretty low level understanding of CF, but are pretty solid writing SQL. Their desired end result is something akin to:

<cfquery name="purchaseTotals">
  SELECT PurchaseId, Total FROM Purchases
</cfquery>

<CF_ASSERT query="purchaseTotals">
  purchaseTotals.Total gte 0
</CF_ASSERT>

The desired output would be a html table with each row being the row from the query that fails the assertion. So to me, the CF_ASSERT tag need to be able to update the current row.

Edit 2:

The main challenge is to allow html in the body of the tag, while still having query values substituted from the appropriate row:

<CF_ASSERT query="purchaseTotals">
  <CF_CONDITION expression="purchaseTotals.Total gte 0">
    <!---error message when expression is false--->
    <cfoutput>
      Purchase #purchaseTotals.purchaseId# has a negative total!
    </cfoutput>
  </CF_CONDITION>
  <CF_CONDITION expression="purchaseTotals.Total eq ''">
    #PurchaseTotals.purchaseId# has a null total, this may be caused by:
    <ul>
      <li>Edge Case 1</li>
      <li>Edge Case 2</li>
    </ul>
  </CF_CONDITION>
<CF_ASSERT>

The output here would be something like:

  Purchase 120 has a negative total!
  Purchase 157 has a negative total!
  Purchase 157 has a null total, this may be caused by:
  • Edge Case 1
  • Edge Case 2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:00:09+00:00Added an answer on May 23, 2026 at 5:00 pm

    Was the functionality described in the above link removed from CF9?

    The internal stuff has definitely changed since the article was written in 2006. But I suspect the exact functionality you are describing may not have existed in any mx version. A key difference between your code and the linked examples is the usage of <cfoutput query=".."> (not just a plain <cfoutput>). The query attribute obviously provides some extra context when evaluating the variables. Remove it (like in your example) and the results are “the value from the first row, not currentRow.”. Even under MX6, which does not bode well for subsequent versions. That exact functionality probably was not removed. It just never worked to begin with.

    If so is there an alternative?

    Like I said earlier, the cleanest approach would be to use array notion ie #query.column[row]#. Given that you seem to have rejected that option, you are basically left with evaluate(). You would need to loop through the query within the parent tag. Then use evaluate to process the subtag expression and content. It is not particularly elegant or simple IMO. But I think that may be good as it gets without array notation, or a ritual sacrifice of some kind.

    ASSERT.cfm

    <cfparam name="attributes.query" type="string">
    
    <cfif thisTag.ExecutionMode is 'start'> 
        <!--- validate attributes.query is a query object --->
        <cfif not ( structKeyExists(caller, attributes.query) AND IsQuery(caller[attributes.query]) )>
            <cfthrow message="Attributes.query [#attributes.query#] is undefined or not a query object">
        </cfif>
    </cfif>
    <cfif thisTag.ExecutionMode is 'end'> 
        <cfset variables[attributes.query] = caller[attributes.query]> 
        <cfloop query="variables.#attributes.query#">
            <cfloop array="#thisTag.assocAttribs#" index="subTag">
                <cfset variables.matchFound = evaluate(subTag.expression)>
                <cfif variables.matchFound>
                    <cfoutput>[#currentRow#] #evaluate(DE(subTag.Content))#</cfoutput><hr>
                </cfif>
            </cfloop>
        </cfloop>
    </cfif>
    

    CONDITION.cfm
    Note: Do NOT use <cfoutput> tags within the tag content.

    <cfparam name="attributes.expression" type="string">
    <cfif thisTag.ExecutionMode is "start"> 
        <cfassociate baseTag="CF_ASSERT">
    </cfif>
    <cfif thisTag.ExecutionMode is "end"> 
        <cfset attributes.content = thisTag.GeneratedContent>
        <cfset thisTag.GeneratedContent = "">
    </cfif>
    

    client has a pretty low level understanding of CF, but are pretty
    solid writing SQL

    Having said all that, are things being implemented this way because it is the best approach or because it is most similar to writing SQL ie comfortable ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a custom function that will let me retrieve a cell
I am trying to write a custom script that will keep a list of
I'm trying to write a custom JSPX tag that reads the value of a
I'm trying to write a custom SQL query that will create a list of
I’m trying to write a custom TCP based long polling server that will serve
I'm trying to write a custom search that will search all categories and individual
I'm trying to write a custom filter for Dynamic data that will allow me
I'm trying to write a custom FxCop code analysis rule that will warn developers
I am trying to write a custom tag. I can write attributes; however, I'm
I'm trying to write a custom WPF ValidationRule to enforce that a certain property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.