1

我对 Javascript 很陌生

此 Javascript 代码将 CSV 文件移动到 Windows 脚本主机上的 Quickbase。所以我每隔一小时就会从 Microsoft Azure 获取数据到这些 CSV,

我使用 powershell 和任务调度程序从 Azure 自动流到 CSV,这些 CSV 文件使用这个 Javascript 代码/任务调度器到 QUICKbase

但是,CSV 文件中没有数据时/CSV 文件为空。此代码导致错误。

但我只是将 CSV 数据作为空移动到 QuickBase 表而不会导致错误。

我应该如何更改代码?

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);
4

1 回答 1

1
var fso = new ActiveXObject("Scripting.FileSystemObject");
var namestart = fso.OpenTextFile(datafile, 1);

var name2 = namestart.AtEndOfStream ? "" : namestart.ReadAll();


{

 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 += name2;
 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);
}
namestart.Close();
于 2015-12-14T22:17:17.180 回答