skip to Main Content
const ss = SpreadsheetApp.getActiveSpreadsheet();

// collect data.
const sourcerange = ss.getRangeByName("b94:h94");
const sourceVals = sourcerange.getValues();


// skip val, gather user email
const email = Session.getActiveUser().getEmail();

const data = {email,sourceVals};

console.log(data);

//append data
const destinationsheet = ss.getSheetByName("test log");
destinationsheet.appendRow(data);

edit: error happening here

const destinationsheet = ss.getSheetByName("test log");
destinationsheet.appendRow(data);

here is the error message

Exception: The parameters ((class)) don’t match the method signature for SpreadsheetApp.Sheet.appendRow.
myFunctionx @ Code.gs:19

2

Answers


  1. If you want the email address of the person that ran the script to be the first value of the row that will be pasted into test log. Try this:

    function myFunction() {
     const ss = SpreadsheetApp.getActiveSpreadsheet();
    
     // collect data.
     const sourcerange = ss.getRangeByName("b94:h94");
     const sourceVals = sourcerange.getValues();
    
    
     // skip val, gather user email
     const email = Session.getActiveUser().getEmail();
     const newVals = [email, ...sourceVals[0]].flat();
     console.log(newVals);
    
     //append data
     const destinationsheet = ss.getSheetByName("test log");
     destinationsheet.appendRow(newVals);
    }
    
    Login or Signup to reply.
  2. Try it this way:

    function myfunk() {
      const ss = SpreadsheetApp.getActive();
      const sh1 = ss.getSheetByName("Sheet1");
      const sourcerange = sh1.getRange("b2:h2");
      const sourceVals = sourcerange.getValues().flat();;
      const destinationsheet = ss.getSheetByName("Sheet2");
      sourceVals.unshift(Session.getActiveUser().getEmail())
      destinationsheet.appendRow(sourceVals);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search