Home > OS >  How to insert into the AppendRow checkbox Google app Script?
How to insert into the AppendRow checkbox Google app Script?

Time:02-15

I create a form using Google Script's service. After entering all information from the form, it will be sent to Google Sheet. How to insert checkbox in appendRow? Doing it my way it just shows "DataValidationBuilder"

Example Picture

function doPost(e) {
  
  Logger.log(JSON.stringify(e));
  
  var destination_id = '1BBwRBt4dVvjRN9-qlxV-87oo5GJECOyM';  // ID OF GOOGLE DRIVE DIRECTORY;
  var destination = DriveApp.getFolderById(destination_id);
  
  var data = Utilities.base64Decode(e.parameter.fileData);
  var blob = Utilities.newBlob(data, e.parameter.mimeType, e.parameter.fileName);
  destination.createFile(blob);
 

  listRecord(e.parameter.applicationDate,e.parameter.name,e.parameter.department,e.parameter.address, e.parameter.timeFrom, e.parameter.timeTo,e.parameter.cardmoney,e.parameter.persionalitycost,e.parameter.feecost,e.parameter.dailyAllowance, e.parameter.fileName, e.parameter.newCheckbox); 
  
  var htmlOutput =  HtmlService.createTemplateFromFile('index');
  htmlOutput.message = 'File Uploaded';
  return htmlOutput.evaluate();                              
   

      
}

function listRecord(applicationDate, address,timeFrom,timeTo,cardmoney,persionalitycost, feecost,dailyAllowance )
{
    var newCheckbox = SpreadsheetApp.newDataValidation();
  newCheckbox.requireCheckbox()
  .setAllowInvalid(false)
  .build();
 
  var url = 'URL';  //URL OF GOOGLE SHEET;
  var ss= SpreadsheetApp.openByUrl(url);
  var recordsSheet = ss.getSheetByName("管理シート");
  recordsSheet.appendRow([setDataValidation(newCheckbox),new Date(),applicationDate,"name","department","work",address, timeFrom,timeTo , feecost,dailyAllowance,"","","","","","","","","","","",cardmoney,persionalitycost]);
  


}

CodePudding user response:

Unfortunately, the data validation cannot be directly used with appendRow. So, in your situation, how about the following modification?

From:

recordsSheet.appendRow([setDataValidation(newCheckbox),new Date(),applicationDate,"name","department","work",address, timeFrom,timeTo , feecost,dailyAllowance,"","","","","","","","","","","",cardmoney,persionalitycost]);

To:

recordsSheet.appendRow(["", new Date(), applicationDate, "name", "department", "work", address, timeFrom, timeTo, feecost, dailyAllowance, "", "", "", "", "", "", "", "", "", "", "", cardmoney, persionalitycost]);
recordsSheet.getRange(recordsSheet.getLastRow(), 1).setDataValidation(newCheckbox);

Note:

  • In your script, it seems that Web Apps is used. In this case, when you modified the Google Apps Script, please modify the deployment as a new version. By this, the modified script is reflected in Web Apps. Please be careful this.
  • You can see the detail of this in the report of "Redeploying Web Apps without Changing URL of Web Apps for new IDE".
  • Related