Coldfusion 9 Session variable error when ran in scheduler

336 views Asked by At

I have a process that when I run it manually, it runs fine with no errors. I have it set up in CF Administrator Scheduler to run daily at 3:00am. It runs and errors out at the same line every time. It has done this for the past week.
Error: Element DATEE is undefined in SESSION. The specific sequence of files included or processed is: C:\data\wwwroot\webapps\cfeis\commonapp\sftp\newpdfs.cfm, line: 45
I know this session variable exists, besauce it is used a couple lines before, and it works fine there.

 <!---Loops through selected folder. If .zip found, extracts all files into same folder--->
<cftry>
  <cfdirectory action="list" directory="#dropfolder#\#session.datee#" name="listRoot">
  <cfloop query="listRoot">
  <!---<cfif #listroot.name# contains ".zip">--->
    <cfif #listroot.name# contains ".zip" and #listroot.name# contains "Writing">
      <cfset session.foldname=#left(listroot.name, len(listroot.name)-4)#>
      <cfif not DirectoryExists("#dropfolder#\#session.datee#\#session.foldname#")>
        <cfset DirectoryCreate("#dropfolder#\#session.datee#\#session.foldname#")>
      </cfif>
      <cftry>
        <cfzip action="unzip" destination="#dropfolder#\#session.datee#\#session.foldname#" file="#dropfolder#\#session.datee#\#listRoot.name#" overwrite="yes" recurse="yes">
        <cfcatch>
          <cfsavecontent variable= "mailmessage">
            <cfoutput>
              #cfcatch.message#
            </cfoutput>
          </cfsavecontent>
          <cfmail from="[email protected]" to="[email protected]" subject="Unzip error" type="html">
            <cfmailpart type="text/html" charset="utf-8">#mailmessage#</cfmailpart>
            <cfmailpart type="text/plain" charset="utf-8">#textMessage(mailmessage)#</cfmailpart>
          </cfmail>
        </cfcatch>
      </cftry>
    </cfif>
  </cfloop>
  <cfcatch>
  </cfcatch>
</cftry>

<cfset session.funzip=0>
<cfset session.funzipArr=ArrayNew(1)>
<cfset sleep(10000)>
<cfdirectory action="list" directory="#dropfolder#\#session.datee#\#session.foldname#" name="listRoot">

The line it errors at is the last line shown in the code above. As you can see, the same variable is used 3-4 times earlier in the code. Can someone help me understand what could be causing this???

1

There are 1 answers

0
James A Mohler On

Sessions and scheduled tasks often don't work together. Sessions are typically are used as a part of a login process. There is no user to login on a scheduled tasks.

If this is your complete code, you can replace session.* with request.*