Estoy usando un script para automatizar la generación de formularios. Básicamente, recorre una lista de elementos, ya que cada uno de ellos debe tener un enlace de formulario diferente. ¿Cómo puedo almacenar los enlaces generados correspondientes a cada grupo en una hoja de cálculo de Google?
Me gustaría tener una hoja de cálculo de esta manera:
Group Link 138 https://docs.google.com/forms/idForm138 139 https://docs.google.com/forms/idForm139Aquí está mi código:
var lista_url=[] var group=[137, 138, 139] function createForm(group) { // create & name Form var item = "Speaker Information Form"; var form = FormApp.create(item) .setTitle(item); // single line text field item = group; form.addTextItem() .setTitle(item) .setRequired(true); // multi-line "text area" item = "Short biography (4-6 sentences)"; form.addParagraphTextItem() .setTitle(item) .setRequired(true); // radiobuttons item = "Handout format"; var choices = ["1-Pager", "Stapled", "Soft copy (PDF)", "none"]; form.addMultipleChoiceItem() .setTitle(item) .setChoiceValues(choices) .setRequired(true); // (multiple choice) checkboxes item = "Microphone preference (if any)"; choices = ["wireless/lapel", "handheld", "podium/stand"]; form.addCheckboxItem() .setTitle(item) .setChoiceValues(choices); var url_form= Logger.log('Published URL: ' + form.getPublishedUrl()); Logger.log('Group: '+group) lista_url.push(url_form) } function generate_Form_links(group){ group.forEach(function(item, index){ console.log(item, index) createForm(item) } } generate_Form_links(group)EDITAR:
Implementar esto genera este error: TypeError: infoArray.join no es una función
function excelformat(lista_url) { var result_table = lista_url var lineArray = []; result_table.forEach(function(infoArray, index) { var line = infoArray.join(" \t"); lineArray.push(index == 0 ? line : line); }); var csvContent = lineArray.join("\r\n"); var excel_file = document.createElement('a'); excel_file.setAttribute('href', 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(csvContent)); excel_file.setAttribute('download', 'Visitor_History.xls'); document.body.appendChild(excel_file); excel_file.click(); document.body.removeChild(excel_file); } excelformat(lista_url)No estoy seguro si entiendo bien tu tarea. Entonces, si tiene las dos matrices: group y links , puede agregar su contenido en la hoja de cálculo de esta manera:
var group = [138, 139]; var links = ['https://docs.google.com/forms/idForm138','https://docs.google.com/forms/idForm139']; function save_arrays_to_spreadsheet(group, links) { var ss = SpreadsheetApp.openById(ss_id); // <-- put the spreadsheet ID here var sheet = ss.getSheets()[0]; // let it be a first sheet for (var i in group) sheet.appendRow([group[i], links[i]]); // add a row }Y no entiendo qué está haciendo esta función en su código:
function generate_Form_links(group){ for (var group=0; group<=group.length ; group=i++){ createForm(group) //call our function for each value in list } } Obtiene el group (¿una matriz?) Y lo convierte en cero var group = 0 , y luego aparece la variable i , etc. Todo me parece un error.
Probablemente, no sé, debería haber:
function generate_Form_links(group) { for (var i=0; i<=group.length; i++) { createForm(group[i]) } }