tags:

views:

68

answers:

2

I have received this error

Element CUSTOMERID is undefined in CLIENT. 
D:\Inetpub\wwwsitecom\wwwroot\rders.cfm:296

on a page that begins with the following code:

<cfif NOT CreateObject("component","User.User").IsLoggedIn()>
    <script type="text/javascript">
        window.location.href='/index.cfm';
    </script>
    <cfabort>
</cfif>

<cfif NOT IsDefined("client.customerid")>
    <cfparam name="client.customerid" default="0">
    <script type="text/javascript">
    alert("We're sorry.");
    window.location.href="/logout.cfm";
    </script>
    <cfabort>
</cfif>

and on line 296

<cfinvoke component="Account" method="getAccessInfo" returnvariable="getInfo">
  <cfinvokeargument name="customerid" value="#client.CustomerID#">
</cfinvoke>

The IsLoggedIn Function has this piece of code

<cfif NOT StructKeyExists(client,"customerid")>
  <cfset strIsLoggedIn = 0>
</cfif>

If ColdFusion processes scripts linearly, how would it have gotten to the undefined client.customerid on line 296 without processing the first parts of the page?

If ColdFusion does not process scripts linearly, how can I prevent this error?

A: 

Make sure you have client variables set up correctly in cfide and check that they are enabled in your Application.cfc file.

anopres
A: 

First, I would check that you aren't creating a variable somewhere (perhaps in an implicit scope in a <cfoutput> or <cfloop> tag) that's named client. Since CF is a late-bound language, that can change the semantics, and references to client.CustomerID will be looking in your local client variable, not the Client scope.

Secondly, if you want to do a redirect, please, please, use <cflocation> instead of doing this crazy JavaScript redirect. Remember that JavaScript is executed on the client side, and it is perfectly possible (and not even that uncommon) for browsers to have JavaScript disabled. <cflocation> results in an HTTP 3xx response being sent, which will work correctly in any browser that implements HTTP, regardless of whether or not JavaScript is enabled. It's also much more secure, since there's no chance of parts of the page being flushed to the client before the redirect.

Daniel Pryden
Daniel, thank you for your input.
davidj