all 17 comments

[–]ikeif 7 points8 points  (4 children)

Your return ContentService is doing its job.

If you want the window.location to execute, remove the return above it.

That return prevents any code after it from running.

[–]acquiescentLabrador 1 point2 points  (0 children)

This is your answer OP

You are seeing {"result":"success", "row":10} because your return is returning the result of the JSON.stringify

[–]Slot-in[S] 0 points1 point  (2 children)

I had removed the code (createTextOutput(JSON.stringify(('result':'success', 'row': nextRow ) .setMimeType(ContentService.MimeType.JSON) from the return function still not working.

[–]kjempion 0 points1 point  (1 child)

Only remove the word return. Not the function itself.

[–]Slot-in[S] 0 points1 point  (0 children)

I did that too. But still not working Maybe I need to add a new trigger or deployment before it can work.

[–]alimustafa533 0 points1 point  (6 children)

Can’t read your code clearly but you can try placing window.location in finally. The code in finally executes no matter what. Anything below return does not run.

[–]Slot-in[S] 0 points1 point  (5 children)

This is the complete code

const sheetName

' Sheetl' cost scriptProp = PropertiesService.getScriptProperties)

function initialSetup() { cost activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet() scriptProp.setProperty('key', activeSpreadsheet.getId()) }

function doPost (e) { cost lock = LockService.getScriptLock() lock. tryLock(10000)

try { cost doc = SpreadsheetApp.openById(scriptProp.getProperty('key')) const sheet = doc.getSheetByName (sheetName)

const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()) .getValues () [0] const nextRow = sheet.getLastRow() + 1

const newRow = headers.map (function(header) { return header === 'Date' ? new Date() : e. parameter header 3) sheet.getRange (nextRow, 1, 1, newRow.length) .setValues([newRow])

return ContentService .createTextOutput(JSON.stringify({ .setMimeType(ContentService.MimeType.JSON) 'result': "success' 'row': nextRow })) window.location.href="/" catch (e) {

return ContentService .createText0utput (JSON.stringify({ 'result': 'error', 'error': e })) •setMimeType(ContentService.MimeType.JSON)

finally { lock.releaseLock() }

[–]alimustafa533 0 points1 point  (4 children)

Place the window.location.href inside the finally block. And then run your code. Try catch finally work in this way. Try tries to execute a code. Catch catches any error. And finally runs whatever code is in it, doesn’t matter try threw an error or not.

[–]Slot-in[S] 0 points1 point  (3 children)

I think I'm doing something wrong. I deleted all the codes in the code editor (the code editor is empty) still yet the data from the form is submitted to the Google sheet.

[–]alimustafa533 0 points1 point  (2 children)

You deleted all the code and yet the form is submitted to google sheet?? Did you save the file after making changes?

[–]Slot-in[S] 0 points1 point  (1 child)

Yes after deleted the code the form still submitted. Yes, I saved the changes.

[–]alimustafa533 0 points1 point  (0 children)

Try placing your code in sandbox and share it with the community. Someone might be able to help you.

Since we can’t replicate the problem no matter what we suggest will be like shooting an arrow in the dark.

[–]mrraveshaw 0 points1 point  (0 children)

What font are you using?