0

I've been using this script for the last two years but it stopped working two months ago with the mention : failed while accessing document with id, is there something that changed with Google?

function copyHoraireJourCovid(){
copySchedule(true);
}

function copyHoraireNuitCovid(){
copySchedule(false);
}

function copySchedule(jourCovid){
var source = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//var destination = SpreadsheetApp.openById('1i-p3X1Y13NgYPNZrl34yHaIOPwm9t8ATsQbt995S4os'); // test
//var destSheet = destination.getSheetByName('DATA'); // test
var destination = SpreadsheetApp.openById('1Aym8F6kHIYaGuYbHyFxiiTC9MUEqHMaLTCvnEBl4a-k');

if (jourCovid)
{
var destSheet = getSheetById(destination, 347147217);

// remove temp sheet
if (destination.getSheetByName("TEMP-Jour-Covid") != null)
{
destination.deleteSheet(destination.getSheetByName("TEMP-Jour-Covid"));
}
var newData = source.copyTo(destination).setName("TEMP-Jour-Covid");
}
else // nuitCovid
{
var destSheet = getSheetById(destination, 1438310663);

// remove temp sheet
if (destination.getSheetByName("TEMP-NUIT-COVID") != null)
{
destination.deleteSheet(destination.getSheetByName("TEMP-NUIT-COVID"));
}
var newData = source.copyTo(destination).setName("TEMP-NUIT-COVID");
}

// copy new data
var sourceRange = newData.getDataRange();//getRange(1, 1, 100, 100);
var sourceValues = sourceRange.getValues();
var rangeDest = destSheet.getRange(sourceRange.getA1Notation());

// clear old data
destSheet.clear();

// copy values
rangeDest.setValues(sourceValues);

sourceRange.copyFormatToRange(destSheet,1, 1, 1, 1); // copy format (bold, background color...)
sourceRange.copyTo(destSheet.getRange(1,1), SpreadsheetApp.CopyPasteType.PASTE_COLUMN_WIDTHS, false); // copy columns width

// copy rows heights
var row_heights = getRowHeights(sourceRange);
var destinationRange = destSheet.getRange(destSheet.getRange(1,1).getRow(),
destSheet.getRange(1,1).getColumn(),
sourceRange.getHeight());
var set_row_heights = setRowHeights(row_heights,destinationRange);

SpreadsheetApp.flush();
}

1 Answer 1

1

This is a VERY widespread problem. It seems to have started early March 2021. This item on Google Doc Editors Help Google Script failure: Service Spreadsheets failed while accessing document with ID provides a good summary of the issue, the issue tracker. It also includes a link to a workaround.

This is the issue tracker. Add a comment to increase the weight of support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.