Question

I want to build kind of an automatic system to update some race results for a championship. I have an automated spreadsheet were all the results are shown but it takes me a lot to update all of them so I was wondering if it would be possible to make a form in order to update them more easily.

In the form I will enter the driver name and the number o points he won on a race. The championship has 4 races each month so yea, my question is if you guys know a way to update an existing data (stored in a spreadsheet) using a form. Lets say that in the first race, the driver 'X' won 10 points. I will insert this data in a form and then call it from the spreadsheet to show it up, that's right. The problem comes when I want to update the second race results and so on. If the driver 'X' gets on the second race 12 points, is there a way to update the previous 10 points of that driver and put 22 points instead? Or can I add the second race result to the first one automatically? I mean, if I insert on the form the second race results can it look for the driver 'X' entry and add this points to the ones that it previously had. Dunno if it's possible or not.

Maybe I can do it in another way. Any help will be much appreciated! Thanks.

Was it helpful?

Solution

Maybe I missed something in your question but I don't really understand Harold's answer... Here is a code that does strictly what you asked for, it counts the total cumulative value of 4 numbers entered in a form and shows it on a Spreadsheet.

I called the 4 questions "race number 1", "race number 2" ... and the result comes on row 2 so you can setup headers.

I striped out any non numeric character so you can type responses more freely, only numbers will be retained.

form here and SS here (raw results in sheet1 and count in Sheet2)

script goes in spreadsheet and is triggered by an onFormSubmit trigger.

function onFormSubmit(e) {
  var sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
  var responses = []
  responses[0] = Number(e.namedValues['race number 1'].toString().replace(/\D/g,''));
  responses[1] = Number(e.namedValues['race number 2'].toString().replace(/\D/g,''));
  responses[2] = Number(e.namedValues['race number 3'].toString().replace(/\D/g,''));
  responses[3] = Number(e.namedValues['race number 4'].toString().replace(/\D/g,''));
  var totals = sh.getRange(2,1,1,responses.length).getValues();
  for(var n in responses){
    totals[0][n]+=responses[n];
  }
  sh.getRange(2,1,1,responses.length).setValues(totals);
}

edit : I changed the code to allow you to change easily the number of responses... range will update automatically.


EDIT 2 : a version that accepts empty responses using an "if" condition on result:

function onFormSubmit(e) {
  var sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2');
  var responses = []
  responses[0] = Number((e.namedValues['race number 1']==null ? 0 :e.namedValues['race number 1']).toString().replace(/\D/g,''));
  responses[1] = Number((e.namedValues['race number 2']==null ? 0 :e.namedValues['race number 2']).toString().replace(/\D/g,''));
  responses[2] = Number((e.namedValues['race number 3']==null ? 0 :e.namedValues['race number 3']).toString().replace(/\D/g,''));
  responses[3] = Number((e.namedValues['race number 4']==null ? 0 :e.namedValues['race number 4']).toString().replace(/\D/g,''));
  var totals = sh.getRange(2,1,1,responses.length).getValues();
  for(var n in responses){
    totals[0][n]+=responses[n];
  }
  sh.getRange(2,1,1,responses.length).setValues(totals);
}

OTHER TIPS

I believe you can found everything you want here.
It's a form url, when you answer this form you'll have the url of the spreadsheet where the data are stored. One of the information stored is the url to modify your response, if you follow the link it will open the form again and update the spreadsheet in consequence. the code to do this trick is in the second sheet of the spreadsheet.
It's a google apps script code that need to be associated within the form and triggered with an onFormSubmit trigger.

It may be too late now. I believe we need a few things (I have not tried it)

  1. A unique key to map each submitted response, such as User's ID or email.
  2. Two Google Forms:
    a. To request the unique key
    b. To retrieve relevant data with that unique key
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top