Looping through structure to find value...

Hello, Please take a look at my screenshot of a structure. Basically, I have single structure with  nested structures. I'm just trying to pull the "discount_id" where "DISCOUNT_CUSTOMER_SPENDING" eq "true". I can't seem to figure this one out. There should only be one available discount that eq "true" so I would think it would fairly simple.

Thanks for the help!

BrianScreenshot of structure
brihol44Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:
<cfloop index="pos" from="1" to="#arrayLen(discountResponse)#">
    <cfif discountResponse[pos].DISCOUNT_CUSTOMER_SPENDING is true>
        Found it at #pos#
        <cfbreak>
     </cfif>
</cfloop>
0
brihol44Author Commented:
ok, I think I did try something similar but I get my screenshot structure from...

<cfset discount = getCartDiscountData(cart=mycart)>

Then comes the structure...

When I add in your code I get the following error.

Variable DISCOUNTRESPONSE is undefined.
0
gdemariaCommented:
If you named the structure "discount"

<cfset discount = getCartDiscountData(cart=mycart)>


Then you should not use the variable name DiscountResponse, instead use the variable "discount" instead
0
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

brihol44Author Commented:
Thank you for your help. I did try before asking for help again...

      <cfloop index="pos" from="1" to="#arrayLen(discount)#">
          <cfif discount[pos].DISCOUNT_CUSTOMER_SPENDING is true>
              Found it at #pos#
              <cfbreak>
           </cfif>
      </cfloop>

but that gave me a error of...

Object of type class coldfusion.runtime.Struct cannot be used as an array
0
brihol44Author Commented:
Thanks for your help. From your code I was able to figure out the rest.

      <cfloop index="pos" from="1" to="#StructCount(discount.discountresponse)#">
          <cfif discount.discountresponse[pos].DISCOUNT_CUSTOMER_SPENDING is true>
              <cfset discount_id = discount.discountresponse[pos].discount_id>
              <cfoutput>#discount_id#</cfoutput>
              <cfbreak>
           </cfif>
      </cfloop>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brihol44Author Commented:
My solution works for what I was needing regarding the structure I have.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.