많은 데이터를 삽입하는 동안 "문서에 액세스하는 동안 실패한 서비스 문서"를 수정하는 방법은 무엇입니까?
Nov 14 2020
많은 수의 테이블을 추가 할 때 오류를 해결하는 방법에서 파생 된 후속 질문 입니다.
아래 코드를 사용하면 500 개의 테이블에 대해 다음 메시지가 표시됩니다. 예를 들어 200에서 잘 작동합니다.Exception: Service Documents failed while accessing document with id
오류는 22 행에서 발생합니다. body = DocumentApp.getActiveDocument().getBody();
시도 할 테이블 템플릿 ID도 있지만 여기에 이미지가 있습니다.
이미지 테이블 템플릿
function RequirementTemplate_Copy() {
var templatedoc = DocumentApp.openById("1oJt02MfOIQPFptdWCwDpj5j-zFdO_Wrq-I48mUq9I-w");
return templatedoc.getBody().getChild(1).copy()
}
function insertSpecification_withSection(){
// Retuns a Table Template Copied from another Document
reqTableItem = RequirementTemplate_Copy();
var body = DocumentApp.getActiveDocument().getBody();
// Creates X number of separated tables from the template
for (var i = 1; i < 501; i++){
table = reqTableItem.copy().replaceText("#Title#",String(i))
body.appendTable(table);
if((i % 100) === 0) {
DocumentApp.getActiveDocument().saveAndClose();
body = DocumentApp.getActiveDocument().getBody()
}
}
}
답변
1 Rubén Nov 14 2020 at 15:48
오류 메시지는 테이블을 추가하기 전에 발생하기 때문에 삽입 할 테이블 수와 관련이없는 것으로 보입니다.
다시 시도해보십시오. 문제가 지속되면 코드가 두 번째 계정에서 실행되는 경우 다른 계정을 사용하여 코드를 시도해보십시오. 첫 번째 계정이 한도를 초과했을 가능성이 있습니다. 게시되지 않은 남용을 방지하기위한 몇 가지 제한이 있으며 이는 변경없이 변경 될 수 있습니다. 발표.
이전 질문에 대한 내 답변 의 코드에 대해 제안 된 수정 사항을 사용하고 반복 제한 수를 1000 및 2000으로 변경하면 정상적으로 작동합니다.
다음 스크린 샷은 1000에 대한 결과를 보여줍니다.

다음은 테스트에 사용되는 코드입니다.
function insertSpecification_withSection(){
startTime = new Date()
console.log("Starting Function... ");
// Retuns a Table Template Copied from another Document
reqTableItem = RequirementTemplate_Copy();
var body = DocumentApp.getActiveDocument().getBody();
// Creates X number of separated tables from the template
for (var i = 0; i < 2000; i++){
table = body.appendTable(reqTableItem.copy());
// if((i % 100) === 0) {
// DocumentApp.getActiveDocument().saveAndClose();
// }
//
}
endTime = new Date();
timeDiff = endTime - startTime;
console.log("Ending Function..."+ timeDiff + " ms");
}
function RequirementTemplate_Copy() {
//---------------------------------------------------------------------------------------------------------------------------------------------------
var ReqTableID = PropertiesService.getDocumentProperties().getProperty('ReqTableID');
try{
var templatedoc = DocumentApp.openById(ReqTableID);
} catch (error) {
DocumentApp.getUi().alert("Could not find the document. Confirm it was not deleted and that anyone have read access with the link.");
//Logger.log("Document not accessible", ReqTableID)
}
var reqTableItem = templatedoc.getChild(1).copy();
//---------------------------------------------------------------------------------------------------------------------------------------------------
return reqTableItem
}
function setReqTableID(){
PropertiesService.getDocumentProperties().setProperty('ReqTableID', '1NS9nOb3qEBrqkcAQ3H83OhTJ4fxeySOQx7yM4vKSFu0')
}