我已經設定了一個可以從外部系統觸發的谷歌應用程式腳本。此腳本將從第三方系統獲取詳細資訊并將它們添加到谷歌作業表行。
function doPost(request) {
try{
var jsonString = request.postData.getDataAsString(); //get the request from KF as JSON String
setLog("\n postData*********************" jsonString "************************************* \n");
setLog("before the row append");
ss.appendRow([jsonString["Name"], jsonString["Age"], jsonString["Contact"]]);
setLog("After the row append");
var returnJson = '{"status": "success"}';
//used to send the return value to the calling function
setLog("/n returnJson****************************" returnJson "************************************* /n")
return ContentService.createTextOutput(returnJson).setMimeType(ContentService.MimeType.JSON);
}
絕對沒有錯誤或警告,但不知何故它不斷將空白行添加到作業表中。
注意:setLog() 是我將值列印到 google doc 以進行除錯的函式。
uj5u.com熱心網友回復:
也許您的腳本不起作用的原因與jsonString.
我request.postData.getDataAsString()在 GAS 檔案中找不到任何參考,所以也許您正試圖在不支持它的物件上呼叫方法,該方法不會引發錯誤,但會回傳undefined.
除錯此問題的一種快速方法是Logger.log(jsonString)在呼叫之前記錄值(使用您的自定義函式或).appendRow()。然后,您可以驗證您的變數是否具有您期望的值。
另一方面,我的建議是使用這種方法:
var jsonString = JSON.parse(request.postData.contents) //Get's the content of your request, then parses it
這種方法存在于檔案中,并且一直適用于我的所有專案。
uj5u.com熱心網友回復:
我認為您應該使用谷歌應用程式腳本對庫姆斯進行排序。之后寫這段代碼ss.appendRow。該列將被排序,所有空白行都會下降。
// Sorts the sheet by the first column, ascending
ss.sort(1)
或者如果錯誤也試試這個
var fl = SpreadsheetApp.getActiveSpreadsheet();
var sheet = fl.getSheets()[0];
fl.sort(1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/404508.html
標籤:
