0

Has anyone here ever worked with Huspot form tracking? I'm trying to set up some code to collect non Hubspot form information and enter it into Hubspot. I'm getting the error "coldfusion.runtime.ScopeCastException: You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members."

Maybe I have some CFM code that's not working in CF 10.? I that's the case, I'm familiar enough with different versions of CF. Could someone please take a look at my code to see if there'e anything that may be causing the error? I've looked at it a lot and tried differnt things but just not having any luck. I have the correct PORTALID and FORMGUID for the url, so those veriables are just place holders for this example.

<!--- Gather tracking cookie from headers and bundle into a json encoded dictionary --->
<cfset Cookies = getHttpRequestData().headers["Cookie"] />
<cfset trackingToken = Cookies["hubspotutk"] />

<cfset hscontext = {}>
<cfset hscontext["hutk"] = trackingToken>

<cfset jsonToken = serializeJSON(hscontext) />

<!--- Submit Data to hubspot, if no lead tracking is being done, only    this part is needed --->
<!--- URL includes portal ID and form GUID --->
<cfhttp url="https://forms.hubspot.com/uploads/form/v2/PORTALID/FORMGUID"
method="POST" >
<cfhttpparam name="firstname" type="FormField" value="#form.firstname#">
<cfhttpparam name="lastname" type="FormField" value="#form.lastname#">
<cfhttpparam name="company" type="FormField" value="#form.company#">
<cfhttpparam name="email" type="FormField" value="#form.email#">
<cfhttpparam name="checkbox" type="FormField" value="#form.newsletter#">
<cfhttpparam name="hs_context" type="FormField" value="#jsonToken#">
</cfhttp>

Thanks!

Rob
  • 35
  • 4
  • Exactly which line is causing the error? It is hard to tell without the complete error message. That is a common error which usually means exactly what it says. You are using one of the variables as if it were a structure, when it is really a simple string. I am guessing it is your usage of the `Cookies` variable. IIRC that value is a *string* containing raw cookie headers. If you want to treat it as a structure, you need to parse it yourself. Side note, the variable name is very similar to the system scope named "cookie". Might want to rename it to avoid accidental collisions or conflicts. – Leigh Jun 30 '15 at 19:05
  • Hi, i'm not sure which line is causing the error. The error message isn't telling me. Is there a way I can get more error information? – Rob Jun 30 '15 at 19:20
  • Well the problem is likely what I said above. You are using the `Cookies` variable as if it is a structure ... when it probably isn't ;-) Dump the variable immediately after the and check it. Regarding debugging, assuming you are on a DEV server, enable full debugging in the CF Administrator. Another option is to wrap the code block in a cftry/cfcatch and cfdump the error inside the catch clause ie . – Leigh Jun 30 '15 at 19:25
  • I Dump the variable, "Cookie"?, immediately after the . Got error: "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. Queries, arrays, and COM objects are examples of complex values. The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag."" – Rob Jun 30 '15 at 21:00
  • This is kind of debugging 101 stuff ;-) Just use the variable name in your code - "cookies" (plural). Also, "dump" that variable (ie use `cfdump`), not `cfoutput` it. Rather than the describing the issue, please edit your question and *append* the new code and any error messages. BTW - If you are new to S.O., it is really is not the best place for extended discussion (and extended comments are often deleted). It is a Q&A site, very different than your typical discussion forum. [Strictly questions and answer, nothing extra](http://stackoverflow.com/tour) ;-) – Leigh Jun 30 '15 at 21:28
  • Add result="httpResponse" to your CFHTTP call and add after the CFHTTP tag closure. – Anit Kumar Jun 30 '15 at 21:59

0 Answers0