Reputation: 33
I am having problem getting an array on the receiving end when passing a array from another WebApp, below is code for the passing side:
//Pass parameter to Holiday Master Sheet webapp
function callRemoteFunc(url, funcName, params) {
var tempUrl = url + "?funcname=" + funcName + "¶ms=" + params;
var response = UrlFetchApp.fetch(tempUrl);
return response.getContentText();
}
var FUNC_WRITE_RECORD = "writeRecord";
function test(timeStamp, email, slackID, formNum, holidayType, startDate, endDate, startTime,
endTime, halfOneDay, daysRested, cancelFlag) {
var dataArray = [];
dataArray.push([
timeStamp, //タイムスタンプ
email, //メールアドレス
slackID, //Slack ID
formNum, //申請番号
holidayType,//休暇の種類
startDate, //開始日
endDate, //終了日
startTime, //開始時間
endTime, //終了時間
halfOneDay, //数日・半日
daysRested, //休み時間
cancelFlag //取り消すフラグ
]);
callRemoteFunc(URL_137, FUNC_WRITE_RECORD, dataArray);
}
And this is the code on the receiving end:
function doGet(e) {
var funcName = e.parameters.funcname;
var params = e.parameters.params;
console.log(funcName[0] + " " + params);
switch(funcName[0]) {
case "writeRecord":
writeRecord(params);
break;
}
}
function writeRecord(dataArray) {
var lastRow = recordSheet.getLastRow();
//Write data into holiday record sheet
recordSheet.getRange(++lastRow, 1, dataArray.length, dataArray[0].length).setValues(dataArray);
}
I keep getting this error " The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues."
Upvotes: 1
Views: 1335
Reputation: 201358
I believe this is what you want:
funcName
and params
to Web Apps using Google Apps Script.The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues.
.In your script, params
is an array. When params
is sent using var tempUrl = url + "?funcname=" + funcName + "¶ms=" + params
, params
is converted to the string like params.toString()
. In this case, var params = e.parameters.params;
in doGet(e)
becomes like [sample1,sample2,sample3,,,]
. When this value is used at setValues
, such error occurs. This is the reason of your error message.
In order to avoid this error, how about the following modification?
When your script is modified, please modify the function of doGet(e)
as follows.
var params = e.parameters.params;
To:
var params = [e.parameter.params.split(",")];
When you modified the script of Web Apps, please redeploy the Web Apps as new version. By this, the latest script is reflected to the Web Apps. Please be careful this.
Upvotes: 4