I have a script that creates a csv. It works fine. My only issue is that I need the file name to have a date at the end of it so it doesn’t get over written each month. I currently have something like this -
var fileNameForExport = (“BankSummaryFee + Math.round(new Date().getTime()/1000)”);
var fileOut = openTextWriter(“c:\out\fileNameForExport.csv”);
I have played around with this and this is where I ended up. My results is simply fileNameForExport.csv.
var fileNameForExport = (“BankSummaryFee + Math.round(new Date().getTime()/1000)”);
var fileOut = openTextWriter(`c:\out\${fileNameForExport}.csv`); // note that double quotes have been changed to back ticks
I have tried both responses above. Neither of them work. I don’t get any errors, just no output. I actually a had to change it to something like this to get the file.
var fileNameForExport = (“BankSummaryFee + Math.round(new Date().getTime()/1000)”);
var fileOut = openTextWriter(“c:\out\fileNameForExport.csv”);
This literally gives a csv file called fileNameForExport. It’s like it isn’t recognizing the variables.
That’s because you’ve got the filename as a string literal which will not interpolate variables. You can copy and paste the code from either post above and it will work.
I did copy and paste from both posts. I did not get any output file at all. It seems as though the only way I get any out put is if I use - var fileOut = openTextWriter(“c:\out\ ( then literally names file whatever you put here) .csv
My full code is below - please note that if I use var fileOut = openTextWriter(c:\out\BankSummary.csv); It works and I get a file. If I use the below code I do not get a file output.
var fileNameForExport = ("BankSummaryFee" + Math.round(new Date().getTime()/1000));
var filepath = "C:\out\\";
var fileext = ".csv";
var filePathname = "filepath + fileNameForExport + fileext";
var fileOut = openTextWriter(filePathname);
var str = [], oneRec, twoRec, prop;
// Add Column names as first line in CSV
oneRec = data.records[0];
twoRec = oneRec.tables["APVendor"];
for (prop in oneRec.fields) {
str.push('"' + prop + '"');
}
for (prop in twoRec[0].fields) {
str.push('"' + prop + '"');
}
fileOut.write(str.join(","));
fileOut.newLine();
str = [];
// Add all values for all records
for (var i = 0; i < data.records.length; i++) {
oneRec = data.records[i];
twoRec = oneRec.tables["APVendor"];
for (var j=0;j<twoRec.length;j++){
for (prop in oneRec.fields) {
str.push('"' + oneRec.fields[prop] + '"');
}
for (prop in twoRec[j].fields) {
str.push('"' + twoRec[j].fields[prop] + '"');
}
fileOut.write(str.join(","));
fileOut.newLine();
str = [];
}
}
//Close file
fileOut.close();
I copy/pasted that bit without checking. Also, the backslash in my template literal is escaping the $ that makes the template work. Adding another slash puts two slashes in the final string. Bummer. Owel’s solution is much better in this case.
I am working in Planet Press Connect. While they say it works off Javascript, It doesn’t always seem to follow the same rules. I had a very hard time with this one but with the code that I provided it gives the exactly waht I need.
I am taking an xml file I am using for the data and in my worklfow, before it goes goes to a pdf I am creating a csv file.