I am writing a google script on top of a spreadsheet based on a google form about Auctioning used cars. My teacher gave me these instructions:
In the spreadsheet add a google script with a function that look for the highest bid and update the Google form field Function 1: Retrieve all the values in the bid column and find the highest value using a loop. Function 2: Open the Google Form and update the form text field (e.g. Current highest bid is $xxxx, please put in your bid). Where xxxx is the highest bid. (reference: https://developers.google.com/apps-script/reference/forms/) Create a trigger in the script that will trigger the above functions and update the Google form.
And here is my code:
function myFunction(e) {
var ss = SpreadsheetApp.getActive().getSheetByName('Used Car Auction')
var form = FormApp.openById('1D0XE9womWv2T_rFYTtc9enQgIhCkxaK8SErxNkTh7NE')
ScriptApp.newTrigger('onFormSubmit')
.forForm(form)
.onFormSubmit()
.create();
var values = SpreadsheetApp.getActiveSheet().getDataRange().getValues()
var bid = values [88000]
var highest = Math.max(bid).toString();
formsetTitle('Used car auction:' + 'The highest bid is:' + highest)
.setDescription ('Description of Form')
.setConfirmationMessage('Thanks for bidding!')
.setAllowResponseEdits(false)
.setAcceptingResponses(true);
}
Google says: TypeError: Cannot call method "getSheetByName" of null.
What am I doing wrong? I've just coded for five days, and this is confusing me.
Other than that, am I on the right track, as per the instructions above?
openById(id)
– Casper