0

I am trying to create a small invoicing organization system using google sheets/drive. I have one sheet I call "tasks", where I plan to control everything from. Some of my columns include, "Client", "Project", "Requirements", "Details", "subcontractor"... As I acquire new tasks/clients, i'd find and append information respective of the task ("Project", "Requirements") to other sheets or, if none exist, create the folders, sheets, and append the respective necessary information from the "tasks" sheet to the new sheets. Some of the sheets will be sent to subcontractors, dependent on whether or not their tasks were updated or new ones were assigned to them in the original "tasks" sheet.

Within the sheets I send to subcontractors, there will be fields for them to fill out (rate, eta..), once filled, I will send that info to a third sheet to apply some margins, extra fees, and then send the info back to the original "tasks" sheet where it will fill appropriate cells.. Once all of the necessary information in a row is filled, it will be prepared and organized into an invoice for the client specified in the "client" column...

Anyways, i've been trying to learn javascript to implement all of this. As I plan to create folders, sheets, and append information based on the values entered in the rows and columns of the "tasks" sheet... I've placed a for loop in an onEdit function that does the following:

    function onEdit(e) {

      var ss = e.range.getSheet().getParent();
      var sheet = e.range.getSheet();
      var row = e.range.getRow();  
      var columns = [1, 2, 3, 4, 5, 6, 7, 8, 9];


       //assign titles as 'keys' to array
       var titles = []

       //assign values of edited row to array
       var values = []

       //create an object to associate the title to the new edited values
       var task = {}



       for(var i in columns){

         titles.push(sheet.getRange(1, columns[i]).getValue());  //push titles
         values.push(sheet.getRange(row, columns[i]).getValue()); //push values of updated row
         task[titles[i]] = values[i]; //add the values to their property names in task object

       }

This works, and I can reference task["Client"], but i'd like to put this loop in a function so that I can use it again. I suppose I could do without it, but array "columns" only represents the columns I will be inputting on the "first round" --- when im sending information out...I will be inputting new information to columns 10-15, then 16-20, as the tasks progress.. and i'd like to run the for loop for those columns without having to create separate loops. To do this i've created the GetInfo function below:

   function GetInfo(row,column){

   for(var i in column){

     titles.push(sheet.getRange(1, column[i]).getValue());  //push titles
     values.push(sheet.getRange(row, column[i]).getValue()); //push values of updated row
     this.task[titles[i]] = values[i]; //add the values to their task

   }
  }

What I am trying to accomplish is similar to what is outlined here. However, the "for(var..in..") is not mentioned in the examples and I think im missing something. In attempt to use the function for the first array of columns ive done this:

var list = new GetInfo(row,columns);

i'd like to reference the task as follows

list.task["client"]

Or var.task["name"], but the above doesn't work. When I toast list.task["Client] or try to append it to another cell, nothing happens - its blank. What am I doing wrong? How do I accomplish this correctly? What should I do?

Any help or guidance would be greatly appreciated. Please.

(other toasts are working, and the respective cell is not blank, without the function the for var in works)

0 Answers0