突然遇到一个问题,即 Google DOCS 服务在调用一些复制元素后失败。
有趣的是,它实际上复制了第一个元素,但是当它进入“for”内的第二个循环时,它失败并给出以下错误:
服务不可用:文件
该脚本在我们公司内部发布后,可以正常运行几个月。
上周突然它停止为所有用户工作,无论他们的浏览器等如何......
它是一个链接到 Google 电子表格的脚本(从中获取信息以生成 Google 文档)。但如果我也从脚本控制台执行或调试它,它也会失败。
在它开始失败后我尝试的是添加几行来 saveAndClose 文档,以防出现过多调用或缓冲问题。
我已经检查过,该项目确实可以访问 Google Docs、Drive 和 Maps API。
要复制的元素是正确的,因为我可以用它们做 Logger.Log...
当它必须复制实际元素(appendParagraph、append ListItem 等)时,它就会失败
我已启用 StackDriver 日志和错误,但它在控制台中没有显示任何日志,只是“失败”。
任何提示或指示将非常感激!
Thanks!
function copyDescription(ID,newDoc,newDocID){
var otherBody = DocumentApp.openById(ID).getBody();
newDoc.saveAndClose();
newDoc = DocumentApp.openById(newDocID);
var docbody = newDoc.getBody();
var totalElements = otherBody.getNumChildren();
//Run through template document and copies to the new one
for( var j = 0; j < totalElements; ++j ) {
var element = otherBody.getChild(j).copy();
var attributes = otherBody.getChild(j).getAttributes();
var type = element.getType();
if (type == DocumentApp.ElementType.PARAGRAPH) {
if (element.asParagraph().getNumChildren() != 0 && element.asParagraph().getChild(0).getType() == DocumentApp.ElementType.INLINE_IMAGE) {
var pictattr = element.asParagraph().getChild(0).asInlineImage().getAttributes();
var blob = element.asParagraph().getChild(0).asInlineImage().getBlob();
}
else {
docbody.appendParagraph(element);
}
}
else if( type == DocumentApp.ElementType.TABLE )
docbody.appendTable(element);
else if( type == DocumentApp.ElementType.LIST_ITEM )
docbody.appendListItem(element);
else
throw new Error("Unsupported element type: "+type);
newDoc.saveAndClose();
}
}