Complex object types cannot be converted to simple values. The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. I believe the issue is security related.
Copy link to clipboard
I've moved this from the Using the Community forum (which is the forum for issues using the forums) to the ColdFusion forum so that proper help can be offered.
Copy link to clipboard
Khalid, can you offer even a simple example, so we might confirm if we see what you do (on CF2018 update 17)?
Also, are you sure NOTHING else changed in your environment? For instance, did anyone change the JVM that CF uses? If so, from what version to what version? That could be as much a cause of strange new errors, if one is not careful about how they do that.
When submitting multiple select values, it through exception at structKeyExists function, it works fine when passing a single select option value but produce error when passing more than one value to structKeyExists funtion.
<select name="user" id="user" size="7" multiple="true">
<option value="#user_id#" <cfif structKeyExists(form, "user") selected</cfif>>#variables.users.user#</option>
If that's a copy and paste you're missing a closing > after the "user")
You can also do that with
#structKeyExists(form,"user") ? 'selected' : ''#
but you probably want to do this
#structKeyExists(form,"user") AND form.user EQ user_id ? 'selected' : ''#
which is the same as
<cfif structKeyExists(form,"user") AND form.user EQ user_id> selected </cfif>
As George has said, the following line contains an error: the closing tag > is missing.
<option value="#user_id#" <cfif structKeyExists(form, "user") selected</cfif>>#variables.users.user#
In any case, you can simplify the code by:
<select name="user" id="user" size="7" multiple="true"> <cfoutput query="users"> <option value="#user_id#" <cfif structKeyExists(form, "user") and form.user eq users.user>selected</cfif>>#users.user#</option><br> </cfoutput> </select>
This is just an example, sorry i missed the closing bracket > . In my real code there are 8 different multiple select options and those were working fine before we applied recent Coldfusion 18 patch and suddenly all of them error out at structKeyExists when we applied new patch. Our administrator revert the new patch and everything start working again.
<select name="user" id="user" size="7" multiple="true">
<option value="#user_id#" <cfif structKeyExists(form, "user")> selected</cfif>>#variables.users.user#</option>
On which line does the error occur? Are you sure it's on the structKeyExists line? Please check application.log and exception.log. The error might be caused by #variables.users#.
In any case, as a test, you should apply Update 11 and then use
Does the error still occur?
"#user_id#" is also a theoretical possibility. But I have assumed it is a database column name.
Try this snippet and let us know:
Build - <cfoutput>#server.coldfusion.productversion#</cfoutput><br><br> <cfset variables.users = querynew("user_id,user","Integer,Varchar",[[1,"user1"],[2,"user2"],[3,"user3"]])> <cfif isdefined("form.submit")> <cfdump var="#form#"><br> </cfif> <cfoutput> <cfform name="f" action="#cgi.script_name#"> <select name="user" id="user" size="7" multiple="true"> <cfloop query="#variables.users#"> <option value="#user_id#" <cfif structKeyExists(form, "user") and Listcontains(form.user,user_id)> selected</cfif>>#variables.users.user#</option> </cfloop> </select> <br><br> <input type="submit" value="Submit" name="submit"> </cfform> </cfoutput>
Copy link to clipboard
The answers offered below have focused on variations of Khalid's code, but with his code (and the variants) the problem is now apparent, and it's NOT what he proposed originally: it is not a problem with structkeyexists at all (it seems to me). Instead, it's a breaking change of behavior in the March 2021 updates for cf2021, 2018, and 2016, and that is undocumented, it seems.
What's changed is how CF processes form posts for fields having multiple values. Prior to the Mar updates, the form field would be available as a LIST of the multiple values, but after the updates instead they show being an ARRAY--which is unexpected, and would indeed break any apps that process fields with multiple values (like the structkeyexists Khalid was using). That's a RESULT rather than the CAUSE of the problem.
I have confirmed this with same code run against all 3 CF versions BEFORE last week's updates were applied and after. And FWIW, I have created a simpler form of the example Saurav offered, which demonstrates the point (see some more text to follow):
Well, I wouldn't have reported my observation if I'd not tested it. 🙂 Here's my screnshot below. We're indeed showing the same version (update and buld number). It's indeed curious. So now we have to wonder about other differences. FWIW, I had tested it on Windows 10 Home and on the Adobe Docker images, with the browser being either Edge (Chromium) or Firefox (latest versions of all).
But then curiously, I have tested on a different machine (happens to be Windows 10 Pro) and the problem does NOT happen there. I would be shocked that could make a difference. I will do more investigation, to find any other possible explanation. Again, below is my screenshot from the machine where I first identified this earlier today. Again, it fit really well as the explanation for what Khalid was saying. We still have not heard from him having tested either of the variants Saurav or I have offered. (Saurav, I have several comments on your blog post about the updates which remain unanswered.)
BKBK, what OS are you running, and what browser, for your testing? And Khalid? And Saurav or anyone else who may try my example code? BTW, I had meant to simplify it still more (removing the name and enctype and the select size. I wanted to make it as simple as could be. I had done that, but somehow I copy/pasted here a variant from before I'd done all that.)
I have now tested with
on Windows 10 Pro.
Same result as in my last post: no errors.
Again folks, the error that @Khalid Saleem reported ("Complex object types cannot be converted to simple values") probably has nothing to do with StructKeyExisis. The cause of the error is likely "#variables.users#" or "#variables.users.user#".
@Khalid Saleem , I have supplied the code with which you can prove or disprove this. Recall:
apply Update 11 and then use
Does the error still occur?
BKBK, you are confirming that it doesn't happen for you on Windows 10 pro like I did. Until you (or others here) might try it on Windows 10 home, my assertion of a bug still stands.
And until we hear from Khalid especially (on whether he sees the form field being an array), we can't know that what I found is not the explanation for his error (in which case your suggestion about the query aspects would not be where the problem is. Indeed, note how my example removed the query entirely. Let's hear if he runs that.)
I am agree with you this issue is not related with structkeyexists. After Coldfusion recent updates posted form values show in an array rather than in a list. This is the real cause of this issue.
Build - 2018,0,11,326016
Thanks for the confirmation, Khalid.
Now we just need to get down to how it is differing on some boxes and not others (for BKBK and even myself). So first, can you report what OS you are running your CF on?
(And while you report using CF2018, and BKBK reported having tested CF2021, I will say again that I had experienced the problem on all 3 recent CF versions...but differently on two boxes, depending on whether running Windows 10 Home [not working] or Pro [working], which I realize is hard to believe could be the explanation. It's all I have to go on for now. And BKBK confirmed he found it working ok after the updates with Pro as well. For the sake of consistency, I'm hoping you will confirm also that you are using Windows 10 Home, or at least something other than Windows 10 Pro.)
I am using Windows Server 2016 OS and ColdFusion Build 2018.0.11.326016.
Thanks for that, Khalid. And I have a work-around for this, finally.
First, I will get to trying things on Windows Server editions soon (again, to try to understand when this problem does and does not happen for different folks).
But until then, the work-around is that it turns out that Adobe added a new applicaiton-level property called sameformfieldsasarray, which controls this behavior. (I really thought I'd seen news of that before, but I could not find it when searching because of course that name is not so obvious. It means, in effect, "render multiple form fields of the same name, or with multuple values, as an array", which is exactly our issue here).
And this update specifically changed that to be a default of true (see the technote for CF2018 update 11, for example, and how it points to the bug report CF-4211056, found at https://tracker.adobe.com/#/view/CF-4211056, which indicates the change). And see a comment I posted there with more, including pointing back to this.
I'll note here that for those who want to try the setting, it's only shown there (and in the CF docs) as something that one would set in an application.cfc, using this.sameformfieldsasarray. For those not using application.cfc, note that it can ALSO be set on the cfapplication tag instead, modifying what you may use already in your application.cfm:
<cfapplication name="whatever" sameformfieldsasarray="false" ... rest of your args>
Sadly, there seems no way to set this behavior ONLY for a given cfm template, if that was of interest.
Finally, beware NOT to just throw in a random new cfapplication tag on the cfm template with the form, in order to set this. Even if it may "work" in solving this problem, there could be other unexpected changes in behavior for your app by doing that.
I still look forward to understanding the variation some of us are seeing, even after applying the updates.
And while the reporter of the bug above indicated that he saw different behavior based on WHETHER he was assessing the form variable within or outside of his application.cfm, in the example I offer above I was of course doing the code in its own template...and for what it's worth I had a blank application.cfm. I didn't think to mention that then, as I never fathomed it could matter. I just always put a blank application.cfm in a new folder I create with any test code, to make sure there's no impact of any application.cfm or cfc in a folder above that testing folder.)
Khalid, let us know if this solution works for you (whether you use application.cfc or .cfm).
Did it work for you, Khalid? If so, great. And in that case, would you want to mark my last reply as the answer for future readers who find this, to save digging through all the discussion. 🙂
There is an other way to fixed complex object types error. If you have few multi-select options and try to submit multiple values then this code covert the array back to list.
<cfif isDefined("form.projectCode") and isArray(form.projectCode)>
<cfset form.projectCode = arrayToList(form.projectCode,",") />
Yep, if one wanted to handle things on a page by page (form by form) basis, sure that's a good tip for them to consider.
BTW, I will add also that I got to test this on a Server 2016 setup, and it too got the form field (with multuple values) as an array. Bottom line: it sure seems this is a "feature" of the updates from last week. Again, it was odd that BKBK and I did NOT experience the problem on Windows 10 Pro. I just really can't fathom how that plays into things.
Finally, thanks for marking a correct answer.
I just ran into this issue with the "sameformfieldsasarray" setting in some of my applications after applying CF 2018 Update 11. Isn't anyone else bothered by the fact that Adobe has changed the default value of a server-wide setting that has been in place for 20+ years?
Yes, there are workarounds but something like this should not be done without warning users. At the very least provide a setting in the Administrator to set the server-wide bahavior back to false. I have 50 or so applications to manage and while not all of them will be impacted by this change a subset of them will be.
Yes, Michael. Agree 100%. And this is not the only breaking change. I didn't raise a stink in this thread, as my focus had been first on finding what was the real cause of the problem, and then on sharing a work-around when I found it.
FWIW, I have been working on a blog post where I would be gathering up the various isssues, and yes I would have made a comment there also about how unfortunate it is that CF updates would break things. It's annoying, absolutely.
But Adobe folks hardly EVER chime in on these forum threads, so complaining about it here is literally "preaching to the choir". You should raise the concern on the Adobe blog post where they announced the March 2021 updates, though I will note that I have raised there several issues which have gotten no response at all. That's part of the reason I am compelled to create my own post, for whatever it's worth.
Finally, on the "bright side", I would point out also that it's not typical that updates introduce breaking changes (especially more than one), but it has happened. My recollection is that it happens every couple of years (so maybe once in every several updates). Can't fathom why, but again yes it should not happen at all.