Estoy tratando de configurar un script que cree un formulario basado en una hoja (que funciona), luego quiero que envíe las respuestas a una hoja específica para que los scripts interactúen con él, conectando manualmente los formularios a la hoja no será práctico ya que se pueden crear formularios múltiples todos los días
cuando ejecuto el script aparece este código de error
Excepción: error inesperado al obtener el método o la propiedad setDestination en el objeto FormApp.Form.
a continuación está mi código, cualquier ayuda será apropiada
function bug() { var sheet = SpreadsheetApp.getActive().getSheetByName('TC'); var value = sheet.getRange("A3").getValue(); var em = sheet.getRange("B3").getValue(); var cos = sheet.getRange("E3").getValue(); var name = sheet.getRange("D3").getValue(); var sup = sheet.getRange("C3").getValue(); var form = FormApp.create(value); var item = form.addMultipleChoiceItem(); item.setHelpText("Name: " + name + "\n\nEmail: " + em + "\n\nQuote No: " + value + "\n\nProject: " + sup + "\n\nTotal Cost: " + cos + "\n\nBy selecting approve you agree to the cost and timeframe specified by the quote and that the details above are correct") .setChoices([item.createChoice('Approve'), item.createChoice('Deny')]); var item = form.addCheckboxItem(); item.setTitle('What extras would you like to add on?'); item.setChoices([ item.createChoice('Damp-Course'), item.createChoice('Wrap'), item.createChoice('Taco') ]); Logger.log('Published URL: ' + form.getPublishedUrl()); Logger.log('Editor URL: ' + form.getEditUrl()); Logger.log('ID: ' + form.getId()); var ssId = sheet.getSheetId(); form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId); var SendTo = "insertgenertic@email.com"; var link = form.getPublishedUrl(); var message = "Please follow the link to accept you Quotation " + form.getPublishedUrl(); //set subject line var Subject = 'Quote' + value + 'Confirmation'; const recipient = em; const subject = "Confirmation of order" const url = link GmailApp.sendEmail(recipient, subject, message); }No puede enviar respuestas de formulario a una hoja existente previamente. Cuando vincula su formulario a una hoja de cálculo de destino, siempre creará una nueva hoja para almacenar esas respuestas, sin importar si usa Apps Script para establecer el destino. Solo puede elegir si será una hoja de cálculo existente o una nueva.
Debido a esto, debe proporcionar la identificación de la hoja de cálculo cuando llame a Form.setDestination(type, id) . Como está proporcionando la identificación de la hoja en su lugar, está recibiendo un error.
Deberías hacer algo como esto:
function bug() { // ... const spreadsheetId = SpreadsheetApp.getActive().getId(); form.setDestination(FormApp.DestinationType.SPREADSHEET, spreadsheetId); // ... }form.setDestination(FormApp.DestinationType.SPREADSHEET, ssId);
Se supone que ssId es la identificación de una hoja de cálculo, no una hoja