服务不可用:复制Google文档时使用DOCS

时间:2019-09-23 02:00:43

标签: google-apps-script google-docs

突然遇到一个问题,即在进行一些复制元素的调用后Google DOCS服务失败。 有趣的是,它实际上复制了第一个元素,但是当它进入“ for”内的第二个循环时,它将失败并给出以下错误: 服务不可用:文档

此脚本过去在我们公司内部发布几个月后正常工作。 上周突然,它停止了对所有用户的运行,无论他们的浏览器如何……

它是一个链接到Google Spreadsheet的脚本(它在其中获取生成Google Docs的信息)。但是,如果我也从脚本控制台执行或调试它,它也会失败。

启动失败后,我尝试尝试添加几行以保存并关闭文档,以防出现调用或缓冲过多的问题。

我已经检查过,并且该项目确实可以访问Google文档,云端硬盘和Maps API。

要复制的元素是正确的,就像我可以执行Logger.Log一样...

当它必须复制实际元素(appendParagraph,追加ListItem等)时,它只会失败

我已经启用了StackDriver日志和错误,但是它在控制台中没有显示任何日志,只是“失败”。

任何提示或指示将不胜感激!

谢谢!

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();
}

}

0 个答案:

没有答案