Home > Mobile >  setValues Exception: Service error: Spreadsheets How to fix range errors?
setValues Exception: Service error: Spreadsheets How to fix range errors?

Time:04-30

function chk(){
  //PDD data setting
  var today=new Date();
  var Date = Utilities.formatDate(new Date(today.getFullYear(),today.getMonth(),today.getDate()), Session.getScriptTimeZone(), "yy-MM-dd");
  
  [{
    sheetName: "Sheet1" ,
    folderID: '(google drive Folder)',
    sheetId: '(sheetId1)',
    tab: ['1', '2', '3', '4'],
    conver: Date
  },{
    sheetName: "Sheet2" ,
    folderID: '(google drive Folder)',
    sheetId: '(sheetId1)',
    tab: ['1', '2', '3', '4'],
    conver: Date
  }{
    sheetName: "Sheet3" ,
    folderID: '(google drive Folder)',
    sheetId: '(sheetId1)',
    tab: ['1', '2', '3', '4'],
    conver: Date
  }].map(obj => cloneValues(obj))
}

  function cloneValues(obj){
  
  let string = obj.conver;
  let A =  obj.sheetName;
  let B = DriveApp.getFolderById(obj.folderID);
  let C = DriveApp.getFileById(obj.sheetId);

  var totalurl =  PastetoDrive.makeCopy('Date '.concat( obj.conver , ' ',obj.sheetName ), dstFolder).getUrl();
  var copy_url = totalurl.split("/");

  let linkSheet = SpreadsheetApp.openById('(Backup Link sheetId)').getSheetByName('LINK');
  linkSheet.appendRow([ string , A , totalurl ]);

  for(let i = 0; i < obj.tab.length ; i   ){

    let fromSheet = SpreadsheetApp.openById(obj.sheetId).getSheetByName(obj.tab[i]);
    let toSheet = SpreadsheetApp.openById(copy_url[5]).getSheetByName(obj.tab[i]);
    
    setValues(fromSheet,toSheet)
  }
}

    function setValues(fromSheet,toSheet){
        let maxCols = fromSheet.getMaxColumns();
        let maxRows = fromSheet.getMaxRows();
        let frvalues = fromSheet.getRange(1,1,maxRows,maxCols).getValues();
        toSheet.getRange(1,1,maxRows,maxCols).setValues(frvalues);
    }

Exception: Service error: Spreadsheets

I am writing and using Google AppScript, a work sheet that performs daily backups. Exception: Service error: Spreadsheets error started to occur about a month ago in a script that I have been using well. Looking at the log, there was a problem with setValues. It seems that the ranges of fromSheet and toSheet don't match.

Daily backups should be stored as values in fromSheet > toSheet .

function setValues(fromSheet,toSheet){
  const range = fromSheet.getDataRange().getValues();
  return toSheet.range;
}

Once I changed the function setValues syntax and used it, I tried using setValues(range) to save it as a value, but it was not enough.

I'm a script beginner. I am testing and using various articles I need on stackoverflow and GitHub by combining and changing them. Can anyone help me again this time?

CodePudding user response:

function setValues(fromSheet,tosheet){

  try {
    const range = fromSheet.getRange(1, 1, tosheet.getMaxRows(), tosheet.getMaxColumns());
    const values = range.getValues();
    const toRange = tosheet.getRange(1, 1, tosheet.getMaxRows(), tosheet.getMaxColumns()).getA1Notation();
    return tosheet.getRange(toRange).setValues(values);

  } catch (e) {
    Logger.log(e);
  }

}

enter image description here to-be

enter image description here as-is

As a result, it was successful. Posting a question and waiting for help from many people, I tried various methods, but nothing improved and I kept getting Service Error: Spreadsheet text.

In the end, I changed some of the setValues syntax and I tried setting the range again, but the same error occurred. After confirming that the result of the clone sheet is the result I want, Decided to avoid this issue. catch(e)

Thank you for your interest.

  • Related