简体   繁体   中英

Google Apps Script: How to set return to my page?

I'm using Google Apps Script to write values from a form to a Google Spreadsheet.

I have the form in my HTML page and its action calls the Google Apps Script to write in the sheet.

Now I'd like to go back to my site with a flag var and show a message (Error or Complete) based on the result of the function.

I know how to create and set the flag variable but I don't know how to "send" it to my page. I was only able to show my flag with something like this (that's the whole function I have in GAS)

function doPost(e){

var id = "";
var name = e.parameter['name'];
var surname = e.parameter['surname'];
var serial = e.parameter['serial'];
var eMail = e.parameter['email'];
var text = e.parameter['text'];
var date = new Date();
var ans = ""
var ctrl= "WIP";

var vals = [id, date, name, surname, serial, eMail, text, ans, flag];
var sheetObj =SpreadsheetApp.openById("myKey").getSheetByName('Requests').appendRow(vals);
return ContentService.createTextOutput(someOutput);
}

Someone knows how to do what I need?

Thanks a lot for your help!

S.

You can do something like this

return ContentService.createTextOutput("Complete").setMimeType(ContentService.MimeType.TEXT);

Or in case of exception return 'Error' from your catch block like this

return ContentService.createTextOutput("Error").setMimeType(ContentService.MimeType.TEXT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM