Skip to main content
2Charlie
Inspiring
December 5, 2017
Answered

How to loop through struct query result?

  • December 5, 2017
  • 7 replies
  • 1640 views

This is what I have.

<cfset inactivePagesReport = Server.CommonSpot.api.getObject('reports')>

<cfset inactivePages = inactivePagesReport.getInactivePages(0)>

<cfdump var="#inactivePages#">

So, how do I loop through each row and only output certain columns like ID, Name, Link columns?

Any help is much appreciated.

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer 2Charlie

    By the way, name, title, id, and so on are not rows. They are column headers.


    Here's how I got it work.

    <cfloop query="#inactivePages.ResultQuery#">

         <cfoutput >

              Title:  #subsiteurl#<br />

         </cfoutput>

    </cfloop>

    7 replies

    Inspiring
    December 5, 2017

    Some options:

    <cfoutput query="inactivePages">

    #inactivePages.ID# #inactivePages.Name# <br/>

    </cfoutput>

    <cfloop query="#inactivePages#">

    #inactivePages.ID# #inactivePages.Name# <br/>

    </cfloop>

    <cfscript>

    for (row in inactivePages) {

    writeOutput(row.id);

    ...

    }

    </cfscript>

    -Nic

    2Charlie
    2CharlieAuthor
    Inspiring
    December 6, 2017

    Thank you so much for the help.

    he following example cause this error:

    Exception: You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

    Message: You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

    <cfscript>

    for (row in inactivePages) {

    writeOutput(row.id);

    ...

    }

    </cfscript>


    And the following code example show this error:

    Message: Attribute validation error for tag cfloop.

    Type: Application

    Detail: The value of the attribute query, which is currently <Reports_GetInactivePages_Result><LimitExceeded type="bool">0</LimitExceeded><resultquery class="array"><item><Date>2016-09-15 14:47:32</Date><Description>About</Description><FileName>index.cfm</FileName><ID type="int">138299</ID><IconPath>/commonspot/dashboard/images/type_icons/pgtype_0.png</IconPath><IconText>CommonSpot Page</IconText><IsUploadedDoc type="bool">0</IsUploadedDoc><Link>/training/01/mathematics/about/index.cfm</Link><LockUserID type="int">0</LockUserID><MyApprovalNeeded type="bool">0</MyApprovalNeeded><MyWIP type="bool">0</MyWIP><OthersApprovalNeeded type="bool">0</OthersApprovalNeeded><OthersWIP type="bool">0</OthersWIP><OwnerID type="int">1001171</OwnerID><OwnerName>SAMPLEML</OwnerName><PageActivationStatus>1</PageActivationStatus><PageType>0</PageType><Scheduled type="bool">0</Scheduled><SubsiteURL>/training/01/mathematics/about/</SubsiteURL><Title>About</Title></item><item><Date>2016-10-06 09:42:15</Date><Description>About</Description><FileName>index.cfm</FileName><ID type="int">139809</I..., is invalid.

    <cfloop query="#inactivePages#">

    ID: #inactivePages.id<br />

    Title: #inactivePages.title# <br/>

    Subsite: #inactivePages.subsiteurl#<br />

    </cfloop>

    And this code example below shows this error:

    Message: Attribute validation error for tag cfoutput.

    Type: Application

    Detail: The value of the attribute query, which is currently inactivePages, is invalid.

    <cfoutput query="inactivePages">

    #inactivePages.ID# #inactivePages.Name# <br/>

    </cfoutput>

    2Charlie
    2CharlieAuthor
    Inspiring
    December 6, 2017

    By the way, name, title, id, and so on are not rows. They are column headers.