title: Losing variable. Element is undefined in VARIABLES
body: <p>We are getting this error in both ColdFusion 9 and ColdFusion 11 servers in production. I originally thought is related to ColdFusion 9 and JavaHeap space or not enough memory. We moved this process to run on a brand new server (ColdFusion 11) where nothing else is running and has a lot of memory and we still get the error. Here is some of the code for this cfm page:</p>
  
  <pre><code>&lt;cfset variables.email_count = 0&gt;
  &lt;!--- email notifications ---&gt;
  &lt;cfoutput query="getOrdersForNotification" group="order_id"&gt;
  
      &lt;cfset variables.inv = ""&gt;
      &lt;cfset variables.usePdf = false&gt;
      &lt;cfif isDefined("application.feature_list_using_pdf_attachment")
              and listFindNoCase(application.feature_list_using_pdf_attachment, "injection scheduler", ",")
          &gt;
          &lt;cfset variables.usePdf = true&gt;
      &lt;/cfif&gt;
  
      &lt;cfthread name="InjectionSchdEmail#dateFormat(now(), 'mmdd')#_#timeFormat(now(), 'HHmmss')#_#getOrdersForNotification.order_id#"
          threadOrderId="#getOrdersForNotification.order_id#"
          threadMemberId="#getOrdersForNotification.member_id#"
          threadNotificationEmail="#getOrdersForNotification.notification_email#"
          threadDateReq="#getOrdersForNotification.date_req#"
          threadStoreCode="#getOrdersForNotification.store_code#"
          threadStoreName="#getOrdersForNotification.store_name#"
          threadToGoLabel="#application.togo_label#"
          threadOrderTotal="#getOrdersForNotification.order_total#"
          threadDelTimeValueFront="#getOrdersForNotification.del_time_value_front#"       
          threadSubject="#variables.subjectAndBodyTemplates.subject#"
          threadBody="#variables.subjectAndBodyTemplates.body#"
          threadFromEmail="#variables.fromEmail#"
          threadLocalNow="#variables.localNow#"
          threadLocalNowInt="#variables.localNowInt#"
          threadDs="#ds#"
          threadUsePdf="#variables.usePdf#"
          &gt;
          &lt;cftry&gt;
              &lt;cfset url.order_id = threadOrderId&gt;
              &lt;cfset url.member_id = threadMemberId&gt;
              &lt;cfsavecontent variable="variables.inv"&gt;
                  &lt;cfinclude template="invoicedeska.cfm"&gt;
              &lt;/cfsavecontent&gt;
  
              &lt;cfset variables.order_day=dateFormat(application.UdfService.toSlashDate(threadDateReq), 'mmm dd')&gt;
  
              &lt;cfset local.subject = threadSubject&gt;
              &lt;cfset local.subject = ReplaceNoCase(local.subject, "[Store Code]", threadStoreCode, "all")&gt;
              &lt;cfset local.subject = ReplaceNoCase(local.subject, "[Takeout Label]", threadToGoLabel, "all")&gt;
              &lt;cfset local.subject = ReplaceNoCase(local.subject, "[Order ID]", threadOrderId, "all")&gt;
              &lt;cfset local.subject = ReplaceNoCase(local.subject, "[Order Total]", NumberFormat(threadOrderTotal,"9,999.99"), "all")&gt;
              &lt;cfset local.subject = ReplaceNoCase(local.subject, "[Required Time]", threadDelTimeValueFront, "all")&gt;
              &lt;cfset local.subject = ReplaceNoCase(local.subject, "[Required Date]", variables.order_day, "all")&gt;
  
              &lt;cfset local.body = threadBody&gt;
              &lt;cfset local.body = ReplaceNoCase(local.body, "[Store Code]", threadStoreCode, "all")&gt;
              &lt;cfset local.body = ReplaceNoCase(local.body, "[Store Name]", threadStoreName, "all")&gt;
              &lt;cfset local.body = ReplaceNoCase(local.body, "[Order ID]", threadOrderId, "all")&gt;
              &lt;cfset local.body = ReplaceNoCase(local.body, "[Order Total]", NumberFormat(threadOrderTotal,"9,999.99"), "all")&gt;
              &lt;cfset local.body = ReplaceNoCase(local.body, "[Required Time]", threadDelTimeValueFront, "all")&gt;
              &lt;cfset local.body = ReplaceNoCase(local.body, "[Required Date]", variables.order_day, "all")&gt;
              &lt;cfset local.body = "&lt;span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: ##000000'&gt;#application.UdfService.multiLiner(local.body)#&lt;/span&gt;"&gt;
  
              &lt;cfif threadUsePdf&gt;
                  &lt;!--- PDF version ---&gt;
                  &lt;cfdocument 
                      format="PDF" 
                      name="variables.attachment" 
                      localURL="#application.pdf_localURL#" 
                      orientation="#application.pdf_orientation#"
                      marginleft="#application.pdf_marginleft#" 
                      marginright="#application.pdf_marginright#" 
                      margintop="#application.pdf_margintop#" 
                      marginbottom="#application.pdf_marginbottom#" 
                      unit="#application.pdf_unit#" 
                      scale="#application.pdf_scale#"
                  &gt;
                      #variables.inv#
                  &lt;/cfdocument&gt;
              &lt;cfelse&gt;
                  &lt;!--- HTML version ---&gt;
                  &lt;cfset variables.attachment = variables.inv&gt;
              &lt;/cfif&gt;
  
              &lt;cfmail to="#threadNotificationEmail#" from="#threadFromEmail#" subject="#local.subject#" type="html"&gt;
                  #local.body#
                  &lt;cfif isDefined("variables.attachment") and threadUsePdf eq false&gt;
                      &lt;cfmailparam
                          file="invoice_#threadOrderId#_#threadLocalNowInt#.html"
                          type="application/html"
                          content="#variables.attachment#"
                          /&gt;
                  &lt;cfelseif isDefined("variables.attachment") and threadUsePdf&gt;
                      &lt;cfmailparam
                          file="invoice_#threadOrderId#_#threadLocalNowInt#.pdf"
                          type="application/pdf"
                          content="#variables.attachment#"
                          /&gt;
                  &lt;/cfif&gt;
              &lt;/cfmail&gt;
  
              &lt;cfset invoice_emailed = application.MessageService.setEmailedInvoice(orderId = threadOrderId, localNow = threadLocalNow, emailAddress = threadNotificationEmail, datasource = threadDs)&gt;
  
              &lt;cfcatch type="any"&gt;
                  &lt;cfset variables.attachment = ""&gt;
                  &lt;cfmail from="erroralerts@monkeymediasoftware.com" to="erroralerts@monkeymediasoftware.com" type="html" subject="POS injection notification email faliure"&gt;
                      &lt;cfif isDefined("cgi.server_name")&gt;
                          Server: &lt;b&gt;#cgi.server_name#&lt;/b&gt;
                      &lt;/cfif&gt;
                      &lt;cfdump var="#cfcatch#" label="cfcatch"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadOrderId#" label="threadOrderId"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadMemberId#" label="threadMemberId"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadNotificationEmail#" label="threadNotificationEmail"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadDateReq#" label="threadDateReq"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadStoreCode#" label="threadStoreCode"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadStoreName#" label="threadStoreName"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadToGoLabel#" label="threadToGoLabel"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadOrderTotal#" label="threadOrderTotal"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadDelTimeValueFront#" label="threadDelTimeValueFront"&gt;&lt;br /&gt;
                      &lt;cfdump var="#local.subject#" label="local.subject"&gt;&lt;br /&gt;
                      &lt;cfdump var="#local.body#" label="local.body"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadFromEmail#" label="threadFromEmail"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadLocalNow#" label="threadLocalNow"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadLocalNowInt#" label="threadLocalNowInt"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadDs#" label="threadDs"&gt;&lt;br /&gt;
                      &lt;cfdump var="#threadUsePdf#" label="threadUsePdf"&gt;&lt;br /&gt;
                      &lt;cfdump var="#variables.inv#" label="variables.inv"&gt;&lt;br /&gt;
                  &lt;/cfmail&gt;
                  &lt;cfrethrow /&gt;
              &lt;/cfcatch&gt;
          &lt;/cftry&gt;
      &lt;/cfthread&gt;
  
      &lt;cfset variables.email_count = variables.email_count + 1&gt;
  &lt;/cfoutput&gt;
  
  &lt;p&gt;&lt;/p&gt;&lt;cfoutput&gt;#variables.email_count# emails sent @ #local_now()#&lt;/cfoutput&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Element EMAIL_COUNT is undefined in VARIABLES.<br>
    The error occurred on line</p>
  </blockquote>