Reputation: 443
I have a page that prints an array with some information to the screen from a session variable (session.stufailedarray). At the top of the page, there a link to export the information to excel. When I try this (in Firefox, IE and Chrome) it works fine. But users keep telling me that they're receiving an error message: "Element stufailarray is undefined is session". I know the variable is there because it just printed it to the screen and I can see it in the debugging. Why would this be happening and only sometimes?
Code that generates error:
<cfset ind=0>
<cfset anArray=arrayNew(2)>
<cfloop array="#session.stufailarray#" index="k">
<cfset ind+=1>
<cfset session.failed=find("UPDATE FAILED: ", "#k#")>
<cfset session.rrr=REFind("\d{9,9}", "#k#")>
<cfset idno=mid("#k#", REFind("\d{9,9}", "#k#"), 9)>
<cfset failed=mid("#k#", Refind("UPDATE FAILED: ", "#k#"), Len(#k#)-(Refind("UPDATE FAILED: ", "#k#")))>
<cfset anArray[ind][1]=#idno#>
<cfset anArray[ind][2]=#failed#>
</cfloop>
<!--- Set content type. --->
<cfcontent type="Application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="filename=load_status.xls">
<cfoutput>
<table cols=2 border=1>
<cfloop from="1" to ="#ArrayLen(anArray)#" index="row">
<tr>
<td>#anArray[row][1]#</td>
<td>#anArray[row][2]#</td>
</tr>
</cfloop>
</table>
</cfoutput>
Upvotes: 0
Views: 1452
Reputation: 1530
According to your question, you have a variable called session.stufailedarray
. However in the code that you posted (which generates the error), you have session.stufailarray
. This is also the error message that you are getting.
"Element stufailarray is undefined is session"
Note that the set (available) variable, the failed is passed tense, which the error variable is in present tense.
Upvotes: 1
Reputation: 595
Try this instead:
<!--- Set content type. --->
<cfset anArray=[]/>
<cfif isDefined(session.stufailedarray)>
<cfset anArray=session.stufailedarray/>
</cfif>
<cfcontent type="Application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="filename=load_status.xls">
<cfoutput>
<table cols=2 border=1>
<cfloop from="1" to ="#ArrayLen(anArray)#" index="row">
<tr>
<td>#anArray[row][1]#</td>
<td>#anArray[row][2]#</td>
</tr>
</cfloop>
</table>
</cfoutput>
Make sure that you configured and enabled application session properly. To use session variables, enable them in two places:
ColdFusion Administrator The Application.cfc initialization code This.sessionManagement variable or the active cfapplication tag. ColdFusion Administrator, Application.cfc, and the cfapplication tag also provide facilities for configuring session variable behavior, including the variable time-out.
Configuring and using session variables
Upvotes: 1