samedi 5 décembre 2020

Redirect/open a tab of another page in my website after a google sheet change

After a visitor finishes to fill a questionnaire on my website, a google sheet is updated. I want that for each update/change that is made in that google sheet that visitor will be redirected to another page in my website (or that page will open in a new tab), according to the changes made to that google sheet (in a specific cell, A1).

My code opens a new tab with the URL that is in cell A1 in that google sheet, but only after I directly make a change in that google sheet. The problem is that If I make the changes by filling the questionnaire in my website (or for that matter through changing another google sheet that is linked to that sheet), nothing happens. How can I change it? In other words, how can I trigger my code so that for every change in A1, that is caused from filling the questionnaire in my website, a window will be open (or the visitor will be redirected to that page)?

 function myFunction() {

 var sheet = SpreadsheetApp.getActiveSheet();
 var startRow = 1; // First row of data to process
 var numRows = 5; // Number of rows to process
 var dataRange = sheet.getRange(startRow, 1, numRows, 5);// Fetch values for each row in the Range.
 var data = dataRange.getValues();
 url1 = data[0];// first column
 var js = '<script>'+
'window.open("'+url1+'".replace(/,/g, ""),"_blank", "width=800, height=600");' +
'google.script.host.close();</script>'
 var html = HtmlService.createHtmlOutput(js)
.setHeight(10)
.setWidth(100);
SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.');   
}

Aucun commentaire:

Enregistrer un commentaire