Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to insert into the AppendRow checkbox Google app Script?

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


}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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".
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading