Edit Specific Rows in Google Drive Spreadsheets

52 views Asked by At

I own a small contracting company. My goal is to create a google script that will allow the contractors to both report their hours and deduct from the total amount of hours that our customers have paid for. Both values are in a google spreadsheet. However, I am having serious trouble trying to put them together. This is what I have so far:

function sessionSubtractor() {

var phone = "+phoneNumber";
var messageBody = "clientName";

var twilio = SpreadsheetApp.openByUrl("spreadsheetURL");
var sheet = twilio.getActiveSheet();
var data = sheet.getDataRange();
var cells = data.getValues().toString();

    for (var i = 1; i<sheet.getLastRow(); i++) {

  if (phone === data.getCell(i,7).getValue()) {

    if (messageBody === data.getCell(i,2) {
     //decrease total session count here 
    }

} 





}

The basic idea I had was to have the program loop through all the data on the sheet, and when the contractor input matched an entry, then to deduct from the total amount of hours the client had bought from the company. Thing is, I don't know how to edit the spreadsheet without hardcoding the cell to edit. Any help would be extremely appreciated.

1

There are 1 answers

0
David Tew On

This is a standard way of structuring the script:

function sessionSubtractor() {
  var phone = "+phoneNumber";
  var messageBody = "clientName";

  var twilio = SpreadsheetApp.openByUrl("spreadsheetURL");
  var sheet = twilio.getActiveSheet();
  var data = sheet.getDataRange();
  var cellsValues = data.getValues();

  for (var i = 1; i < cellsValues.length; i++) {
    if (phone === cellsValues[i][7]) {
      if (messageBody === cellsValues[i][7]) 
      {
        //decrease total session count here 
      }
    } 
  }
}

(Please note that I make mistakes, and I don't really know what your data is like so as to interpret what you are trying to achieve ... so, in other words, my script might not do what you think it should.)