• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF11 cffile write failing on a few files with no errors

Community Beginner ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

I inherited some order entry websites that have worked seemingly flawlessly for the past 3 years. Today I learned that 3 files didn't get sent to a customer last week, and I can confirm these files they should have gotten were never created on the server. However, I can find no entry in any of the log files (C:\ColdFusion11\cfusion\logs) that would indicate what the issue was. I would have expected some kind of exception to occur if a file could not be created or is that not that case? This part of the code does not contain any cftry / cfcatch blocks. I'll include the relevant parts here:

<cfset OrderPath = #GetTempDirectory()#> 

<cfset DateTime = DateFormat(now(),"yyyymmdd") & "_" & TimeFormat(now(),"hhmmssllll")>

<cfset OrderFileName = ("WB" & "_" & #DateTime# & ".ORD")>

<!--- Check if order file exists - if so, delete it --->

<cfif FileExists(#GetTempDirectory()#&#OrderFileName#)>  

  <cffile action="delete" file="#GetTempDirectory()##OrderFileName#">

</cfif>

<cfset HeaderRec ="H#x2tab##x2Cust##x2tab##x2OrdDate##x2tab##x2ContactName##x2tab##x2PO##x2tab##x2SubTotal##x2tab##x2PST##x2tab##x2GSTHST##x2tab##x2Total##x2tab##x2Comments##x2tab##x2ShipToAddr1##x2tab##x2ShipToAddr2##x2tab##x2ShipToCity##x2tab##x2ShipToProvince##x2tab##x2ShipToCountry##x2tab##x2ShipToPostal##x2tab##x2ShipToDate#"> <!--- I didn't include all those cfsets but if nothing else the first H would always be written, right? --->

<!--- Write Header record to file --->

<cffile action="write"

file="#GetTempDirectory()##OrderFileName#"

output="#HeaderRec#">

<cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">

     <cfset DetailRec ="D#x2tab##x2Item##x2tab##x2Qty##x2tab##x2Price##x2tab##x2Mask##x2tab##x2UOM##x2tab##x2PriceOver#"> <!--- similar to the HeaderRec --->

       <!--- Write Detail record to file --->

     <cffile action="append"

     file="#GetTempDirectory()##OrderFileName#"

     output="#DetailRec#">

</cfloop>

<cfset source = trim(#OrderPath#) & trim(#OrderFileName#)>

<cfset dest = trim(#Session.ftpdataoutdir#)>

<cffile action="copy" source="#source#" destination="#dest#">

<cflocation url="thankyou.htm" addtoken="no">

The thankyou.htm page includes an email order confirmation which they did receive so nothing prevented the page from processing all the way to the end. However, going to C:\ColdFusion11\cfusion\runtime\work\Catalina\localhost\tmp, which is where all of our files are written initially, these few files don't exist while hundreds of others that continue to be written there. How can I tell why these 3 files were not written so I can prevent it in the future?

Views

739

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 23, 2019 Jan 23, 2019

Turns out this was a false alarm. We have 2 identical servers and somehow they connected to the secondary one for no reason so the files were on it.

Thanks for the tips though.

Votes

Translate

Translate
Community Expert ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

I find it hard to read the many # symbols. You could make your code more efficient, hence more maintainable, as follows:

<cfset OrderPath = getTempDirectory()>

<cfset DateTime = dateFormat(now(),"yyyymmdd") & "_" & TimeFormat(now(),"hhmmssllll")>

<cfset OrderFileName = ("WB" & "_" & DateTime & ".ORD")>

<cfset tempOrderFile = OrderPath & OrderFileName>

<!--- Check if order file exists - if so, delete it --->

<cfif fileExists(tempOrderFile)>

  <cffile action="delete" file="#tempOrderFile#">

</cfif>

<cfset HeaderRec ="H" & x2tab & x2Cust & x2tab & x2OrdDate & x2tab & x2ContactName & x2tab & x2PO & x2tab & x2SubTotal  & x2tab & x2PST & x2tab & x2GSTHST & x2tab & x2Total & x2tab & x2Comments & x2tab & x2ShipToAddr1 &  x2tab & x2ShipToAddr2 & x2tab & x2ShipToCity & x2tab & x2ShipToProvince & x2tab & x2ShipToCountry & x2tab & x2ShipToPostal & x2tab & x2ShipToDate>

<!--- Write Header record to file --->

<cffile action="write"

        file="#tempOrderFile#"

        output="#HeaderRec#">

<cfloop from="1" to="#ArrayLen(Session.Cart.ItemID)#" index="ThisItem">

    <cfset DetailRec = "D" & x2tab & x2Item & x2tab & x2Qty & x2tab & x2Price & x2tab & x2Mask & x2tab & x2UOM & x2tab & x2PriceOver>

      <!--- Write Detail record to file --->

    <cffile action="append"

            file="#tempOrderFile#"

            output="#DetailRec#">

</cfloop>

<cfset source = tempOrderFile>

<cfset dest = trim(Session.ftpdataoutdir)>

<cffile action="copy" source="#source#" destination="#dest#">

<!--- Check if order file exists - if so, then redirect to thankyou page --->

<cfif fileExists(tempOrderFile)>

  <cflocation url="thankyou.htm" addtoken="no">

<cfelse>

<!--- You might want to include code here to inform the user something went wrong --->

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

Question: is it your intention not to use the loop index ThisItem within the loop?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

ThisItem is used many times within the loop, but just like I had commented on HeaderRec (see below) I didn't include all the cfset statements used for DetailRec since they aren't relevant to the issue.

<!--- I didn't include all those cfsets but if nothing else the first H would always be written, right? --->

As for the # symbols, this is how it was already coded so I had no reason to change it since it works.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

topshotrhit  wrote

As for the # symbols, this is how it was already coded so I had no reason to change it since it works.

Using hashtags where they are not needed can impact performance.  Also, as BKBK pointed out, not using hashtags in code where you don't need them makes code easier to read.

Most CF sites/apps will have hundreds of .cfm/cfml documents, which makes it difficult to weed through and remove the unnecessary pound signs.  But it would generally be a good idea to at least start doing just that.  You won't get it all corrected in one day, it could take weeks, but it could speed things up.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

topshotrhit  wrote

As for the # symbols, this is how it was already coded so I had no reason to change it since it works.

Here's a reason: research has shown that, in the life time of a software application, 60 to 70% of the costs are maintenance costs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

LATEST

I certainly agree with that. Part of the issue in my case at least is that unless it is billable, I don't truly get paid for it so there's not much motivation for spending much time on something that a client didn't request or fixing a bug. I have cleaned up things when doing that.

I guess the other part in this particular case is why I don't need the # within HeaderRec. I thought that was supposed to tell CF to provide the value of all those CF variables per the doc. Perhaps you didn't understand my comment that I left out a bunch of cfset statements since they weren't relevant. Or am I not understanding something properly? Here is the full code for that section (ignore the fact many say not used):

<cfset x2tab = chr(09)> <!--- tab delimiter --->

<cfset x2Cust = #CustId# & "-" & #Csub#> <!---Customer # 123456-000 format --->

<cfset x2OrdDate = " "> <!--- "yyyymmdd" NOT USED --->

<cfset x2ContactName = " "> <!--- Distributor contact name, NOT USED --->

<cfset x2PO = #DateTime#> <!--- internal PO#  (Date/Time)  "yyyymmdd_hhmmssllll"  25 max length) --->

<cfset x2SubTotal = " "> <!--- NOT USED --->

<cfset x2PST =  " "> <!--- NOT USED --->

<cfset x2GSTHST =  " "> <!--- NOT USED --->

<cfset x2Total =  " "> <!--- NOT USED --->

<cfset x2Comments = #Session.CustPO#> <!--- Using for Customer PO# entered--->

<cfset x2ShipToAddr1 =  " "> <!--- NOT USED --->

<cfset x2ShipToAddr2 =  " "> <!--- NOT USED --->

<cfset x2ShipToCity =  " "> <!--- NOT USED --->

<cfset x2ShipToProvince =  " "> <!--- NOT USED --->

<cfset x2ShipToCountry =  " "> <!--- NOT USED --->

<cfset x2ShipToPostal =  " "> <!--- NOT USED --->

<cfset x2ShipToDate =  "#DateFormat(FORM.DelDate, "yyyymmdd")#"> <!---  format yyyymmdd --->

<cfset HeaderRec ="H#x2tab##x2Cust##x2tab##x2OrdDate##x2tab##x2ContactName##x2tab##x2PO##x2tab##x2SubTotal##x2tab##x2PST##x2tab##x2GSTHST##x2tab##x2Total##x2tab##x2Comments##x2tab##x2ShipToAddr1##x2tab##x2ShipToAddr2##x2tab##x2ShipToCity##x2tab##x2ShipToProvince##x2tab##x2ShipToCountry##x2tab##x2ShipToPostal##x2tab##x2ShipToDate#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

Turns out this was a false alarm. We have 2 identical servers and somehow they connected to the secondary one for no reason so the files were on it.

Thanks for the tips though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation