Skip to main content
Inspiring
August 14, 2023
Answered

complex object types cannot be converted to simple values

  • August 14, 2023
  • 2 replies
  • 4925 views

I am moving an old application which is on a CF11 install to my CF2021 install.

the code has worked fine for 10 years under CF11

 

i have code where after i am adding a product to my cart it its updating the database with the cart product information. it is running this code as part of a UPDATE cfquery and upating a user table:

 

SET PreviousProduct_ID = '#Listfirst(Form.Product_ID)#',

 

CF is complaining - 

Complex object types cannot be converted to simple values.
but it is not a complext object it is a simple list productid numbers with commas

this is the variable output in the CF debug
PRODUCT_ID=5332,5333,5334,5335,5336,5337,5338,5339,5340,5341,5342,5343,5344,5345,5346,5347,5348,5349,5350
that is a list? not a complex object? works fine in CF11 but not in 2021 and i can not for the life of me fiture it out.
Please help.


 

 

    This topic has been closed for replies.
    Correct answer Charlie Arehart

    Ok, there you go. It IS indeed a complex object, an array as you note. As for how it's happening, it was a change Adobe curiously (and quietly) introduced a couple of years ago (but then soon reverted). In CF2018 update 11 and CF2021 update 1, they started treating the multiple values of any form fields that had the same name as an array, instead of as a list as in the past. That seems to be what you're experiencing. This was reverted in CF2018 update 12 and CF2021 update 2.

     

    Technically, the feature is an old one, introduced in CF10, where Adobe also introduced a way to control that behavior, either with a cfapplication attribute for those using that and/or application.cfm, or as a property of application.cfc for those using that, called sameFormFieldsAsArray. Initially it defaulted to False. Only for that one update did it revert to defaulting to True. Since then, it again defaults to false.

     

    In any case, if you're getting an array and want a list, you'd want to set it to false. Don't make a mistake that I and many have, of leaving off the "s" after "field". It's:

     

    sameFormFieldsAsArray="false"

     

     

    And if you want to view what value is affecting your application, use cfdump to view the result of CF's getapplicationmetadata() function, which will report this sameformfieldsasarray being yes or no, depending on your setting or the default (it does not indicate if settings are set or picked up as defaults).

     

    For more on the sameformfieldsasarray issue from that timeframe in 2021-2022, see another discussion thread back then, and my comment offering this solution then https://community.adobe.com/t5/coldfusion-discussions/coldfusion-2018-update-11-error/m-p/11954596#M188253

     

    Let us know how it goes. 

    2 replies

    rickmazAuthor
    Inspiring
    August 15, 2023

    so i put the abort right before the query and as suspected there was no error - i would not expect there to be because the line that caused the error did not run so thats good.

    Now i did the var dump  and i get this:

     

    array118632186431865418665186761868718698187091871101872111873121874131875141876151877161878171879181880

     

    so it appears it is an array? not sure how that is but it worked in CF11 so CF11 must have allow this and now is'nt?

     

    but i dont know how to fix it 

    rickmazAuthor
    Inspiring
    August 15, 2023

    This is the cf var dump that it is showing

    Charlie Arehart
    Community Expert
    Community Expert
    August 15, 2023

    Well, we have to take your word for it that the error is indeed referring to that variable. Can you confirm that somehow? For instance, you could put a <cfabort> before the cfquery doing the sql update.  Does the error still happen? If not, that's NOT what's causing the error.

     

    Second and as important, don't rely on the debug output. At the same time as the above, and before the cfabort, put in a <cfdump var="#form.Product_ID#"> to see what is in that var right before trying that update. There are reasons the two results could vary. 

    /Charlie (troubleshooter, carehart. org)