Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updating existing data on google spreadsheet using a form?

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.

like image 537
jupcan Avatar asked Feb 14 '14 15:02

jupcan


People also ask

How do I link a Form to an existing spreadsheet?

That's great for quick form results, but for more tools to analyze answers, you can link your form to a Google Sheets spreadsheet. Just click the green Sheets icon in the Responses tab or click Select response destination in the menu, then create a new spreadsheet or select an existing one to store the answers.

Can Google Forms auto populate from spreadsheet?

Yes it is. Use a Form script and update the information from the spreadsheet using a trigger on the FORM OPEN. Here is an example that gets data from two different sheets and insert data in a combo box and into a multiple choice control.

How do I update data in Google Spreadsheet?

Visit Google Sheets and open the spreadsheet where you want to locate and update your data. Click Edit > Find and Replace from the menu. When the Find and Replace window displays, enter the data you want to locate in the Find box. Then, in the Replace With box, enter what you want to update it with.


2 Answers

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);
}
like image 58
Serge insas Avatar answered Nov 13 '22 17:11

Serge insas


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.

like image 41
Harold Avatar answered Nov 13 '22 19:11

Harold