1

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 + "&params=" + 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."

1

1 Answer 1

4

I believe this is what you want:

  • You want to send funcName and params to Web Apps using Google Apps Script.
  • You want to know the reason of the error message of The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues..

Issue and solution:

In your script, params is an array. When params is sent using var tempUrl = url + "?funcname=" + funcName + "&params=" + 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?

Modified script:

When your script is modified, please modify the function of doGet(e) as follows.

From:
var params = e.parameters.params;
To:
var params = [e.parameter.params.split(",")];

Note:

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.

References:

Sign up to request clarification or add additional context in comments.

5 Comments

Similarly, "Please think of this as just one of several possible answers" is indeed how Stack Overflow works, and we expect readers to know that. You've helpfully informed readers about this 1,022 times, which is an additional editing burden. Could I trouble you to reply to say that you will stop doing this? This really is the antithesis of the writing style we expect at Stack Overflow.
@halfer Thank you for your comments and edits. 1. I think that my English skill is not good. So I'm always worry about whether I could correctly understand about the questioner's goal, and what I want to tell can be told to the questioners. So I add "apologize". 2. I use "Please think of this as just one of several possible answers" because I think that my answer and proposals are not only one answer for the question.
@halfer From your comments and edits, I could understand about them. I couldn't notice that to use "apologize" and "Please think of this as just one of several possible answers" in the answer is not matched to the style of Stackoverflow. I deeply apologize for this. By your comments, I would like to change the style of my answer. Thank you, again.
@DarkWheel Thank you for replying. I'm glad your issue was resolved.
No apologies necessary @Tanaike. Yes, brevity is generally preferred here. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.