0

I am new to app scripts, java, and any coding I've been trying to teach myself for about a week now, so please bear with me. Here is my end goal and what I'm trying to accomplish. I have a form set up so that when a call comes in my team can simply input the customers data and it dumps that data to form responses sheet. I then want that data to transfer to a master sheet leaving the raw data from the form intact.
From the master sheet I need 6 sheets of subset data that can be filtered, columns rearranged, added and data edited so that the edits will also update the master sheet.

In other words I would like to have a tab for each team member filtered by field service group. Each team member needs to be able to rearrange the columns, sort filter and edit on their respective sheet. When these changes are made that data should in turn update on the master sheet as well.

What I've accomplished...Once WO status is set to Invoiced that row should then be moved to an archive sheet and deleted from the master list. I also need the option of having the archived rows moved back to the master sheet if the WO has to be re-opened. So far I have managed to come up with the following code that moves the row between sheets based on a user defined condition such as "Open", "Done", or "Complete"......This seems to work fine though there may be a more elegant or efficient way to accomplish it.

https://docs.google.com/spreadsheets/d/1TOj72oc3Lboku0IvhsgHFi0utKG8rIZqT7IFlsKion4/edit?usp=sharing

The status change function below seems to work fine on my tests. The on formsubmit function is the one i'm struggling with.

     function onEdit(e) {//"e" receives the event object
  var range = e.range;//The range of cells edited

  var columnOfCellEdited = range.getColumn();//Get column number


    enter code here

  if (columnOfCellEdited === 6) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = e.source.getActiveSheet();
  var r = e.source.getActiveRange();
  var C = 6 // column A=1, B=2, C=3, etc.
  var V1 = "Open" //Variable #1 user defined
  var V2 = "Review"
  var V3 = "Invoiced"
  var TS1= "Open"    //target sheet 1 name
  var TS2= "Review"  //target sheet 2 name
  var TS3= "Invoiced"    //target sheet 3 name
  var SS1 = "Test Work order Tracker"




  if(ss.getName() == SS1 && r.getColumn() == C && r.getValue() == V3 ) {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName(TS3);
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }
  else if(ss.getName() == SS1 && r.getColumn() == C && r.getValue() == V2 ){
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName(TS2);
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }
   else{
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName(TS1);
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }
}
}


    // set up on form submit trigger to copy data to masterlist
        function onFormSubmit(e)

      var responses = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Open");
      var masterList =  SpreadsheetApp.openById('1TOj72oc3Lboku0IvhsgHFi0utKG8rIZqT7IFlsKion4').getSheetByName("OriginResponse");
      var lastrow = responses.getLastRow();
      var col = responses.getLastColumn();
      var row = responses.getRange(lastrow, 1, 1, col).getValues();

      masterList.appendRow(row[0]);
  • Hey, @WTslick007 welcome to Stackoverflow! Could you please describe **your issue** a bit more? What have you tried (onFormSubmit function), what error/issue are you getting? What are you trying to accomplish with that function? Regards – carlesgg97 Oct 24 '19 at 13:39
  • There's no method `getSpreadsheetByName` You want to use `open()` - the [documentation](https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#openfile) doesn't help if you want to open by name, but this topic would be helpful: [Open Google Apps Spreadsheet by name](https://stackoverflow.com/q/36868904/1330560). – Tedinoz Oct 26 '19 at 01:29
  • @WTslick007 Have you resolved your problem? – Tedinoz Nov 02 '19 at 23:03
  • Yes, I did... Thank you very much for the advice. I have edited the code to reflect the changes made. I am however having issues with the onedit function. It works flawlessly if I use test data and between Review and Invoiced sheets however actual form responses will not move. Any idea why? – WTslick007 Nov 04 '19 at 16:18

0 Answers0