I am very new to Javascript
This Javascript code moves CSV files to Quickbase on Windows Script Host. so I get the data every one hour from Microsoft Azure to these CSV,
I made autoflow from Azure to CSV using powershell and task scheduler, these CSV files to QUickbase by using this Javascript code/Task Schduler
However, when there is no data on CSV file/CSV file is empty. this code causes the error.
but I would just move the CSV data as empty to QuickBase Table without causing Error.
How should I change the code?
var datafile = "3-Month Free Trial-SQLDataServer.csv";
var dbid = "beegbjn3e2";
var username = "useranme";
var password = "Helloworld";
var subdomain = "Mycompany";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var csv = fso.OpenTextFile(datafile, 1).ReadAll();
fso.close;
WScript.Echo(csv);
var url = "";
url += "https://" + subdomain + ".quickbase.com/db/" + dbid;
url += "?act=API_ImportFromCSV";
url += "&username=" + username;
url += "&password=" + password;
WScript.Echo(url);
var request = "";
request += "<qdbapi>";
request += "<skipfirst>1</skipfirst>";
request += "<records_csv><![CDATA[";
request += csv;
request += "]]></records_csv>";
request += "</qdbapi>";
WScript.Echo(request);
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", url, false);
xmlhttp.setRequestHeader("content-type","text/xml");
xmlhttp.send(request);
WScript.Echo(xmlhttp.responseText);