Skip to main content
Inspiring
April 14, 2009
Question

createData in cfloop array question?

  • April 14, 2009
  • 2 replies
  • 499 views

I have an array with shop items, the cfdump is:

-------

1

AMOUNT  1
ID      8FD457C0-2399-11DE-98AA000C7674A083

2

AMOUNT  1
ID      6A1B47A0-1895-11DE-A201000C7674A083

-------

Then i want to loop the array and perform a createData (writes new record to database) action, when i
have one item in the array it works, when i have 2 items in the array
it doesn't work.

I thought it must be because somehow the createData creates a sort of
duplicate record error, but then again, i use the to address only
the current array loop item.

I don't see it anymore, anyone had a fresh insight?

<cfset sailsobj = createObject
('component',application.stcoapi.shopproductbehaviour_sails.packagepath) /


<cfloop index="i" from="1" to="#arraylen(session.shopcart)#">

<!--- set product sails --->
<cfset sailsprops.productobjectid = session.shopcart.id>
<cfset sailsprops.productamount = session.shopcart.amount>
<cfset sailsobj.createData(stProperties=sailsprops)>

</cfloop

    This topic has been closed for replies.

    2 replies

    Inspiring
    April 14, 2009

    So the problem was that i wasn't initializing the properties for each loop, therefore were using values from the previous loop for all next loops, that gave an error in the createdata (write record to database) function, i think a duplicate record error a like thing.

    Inspiring
    April 14, 2009

    When in doubt, look at your data.  Inside your loop, either output or dump session.shopcart.id and session.shopcart.amout.  Do you see what you expect to see?

    What might be relevent is that you don't really have an array as much as you have a bunch of structures.  That might be messing you up.

    Inspiring
    April 14, 2009

    The data was correct, i had an answer on:http://groups.google.com/group/farcry-dev/browse_thread/thread/36734838ec832aa8.

    So the problem was that i wasn't initializing the properties for each loop, therefore were using values from the previous loop for all next loops, that gave an error in the createdata (write record to database) function, i think a duplicate record error a like thing.

    Thanks!