XPages SSJS 代码给出错误 "One or more of the source document's attachment are missing"

XPages SSJS Code giving error "One or more of the source document's attachment are missing"

这一行

publishedDoc.save(true, false, true);

偶尔会在网络上保存的文档中引起上述错误,其中内联图像是通过 CKEditor 添加的。我无法确定导致此错误的情况,因此非常感谢任何提示或评论。

这里有更多的代码,因此您可以获得该调用的上下文:

function postSavePage(doc) {
    if(doc.getItemValueString("status")=="To Be Published" || doc.getItemValueString("status")=="Save as Current Version" ) {
        var saveAsCurrent = doc.getItemValueString("status")=="Save as Current Version";
        var publishedDoc:NotesDocument = getCurrentlyPublishedDoc(doc);

        if(!publishedDoc) {
            publishedDoc = doc;
            publishedDoc.replaceItemValue("status", "Published");
            PublishedDoc.replaceItemValue("VERNUMBER", 1);
        } else {
            //******
            //copy draft to temp doc 
            var tmpDoc:NotesDocument = database.createDocument();
            doc.copyAllItems(tmpDoc, true);

            //copy published to draft (for archiving)
            publishedDoc.copyAllItems(doc, true);
            if(saveAsCurrent) {
                doc.replaceItemValue("status", "Archive (Saved As Current)");
            } else {
                doc.replaceItemValue("status", "Archive");  
            }

            //copy temp (newly published) to published doc
            tmpDoc.copyAllItems(publishedDoc, true);

            //Make sure we set the version number if saved as current version
            if(saveAsCurrent){
                publishedDoc.replaceItemValue("VERNUMBER", doc.getItemValueInteger("VERNUMBER"));
            }

            publishedDoc.replaceItemValue("status", "Published");
            updateRevisionData(doc);
            if(!saveAsCurrent) { 
                setVersion(doc);
            }

            //save docs
            doc.save(true, false, true);
            publishedDoc.save(true, false, true);
        }
    }
}

基本上,此代码管理 CMS 类型应用程序中的版本控制。由于现有内容中已经存在许多文档链接,因此我需要保留已发布文档的 UNID。这解释了已发布文档、临时文档和文档(即草稿)之间美妙的小舞蹈:草稿内容转到已发布版本,已发布版本转到存档。

我将持久性设置为 "keep pages on disk" 并将持久性模式设置为 "Entire page content"。虽然不确定它是否有所作为...

有什么线索吗? :D

错误的事件。如果您想在写回磁盘时修改文档数据,请使用 QuerySave 并且不要对当前文档执行 document.save() 。

因此您可能需要拆分代码。

背景:XPages 将附件(内联图像是附件)上传到临时位置并跟踪它们。当您保存时,它们会被添加到笔记中并被丢弃。指向临时文件的指针仅在事件链(QuerySave、实际写入磁盘、PostSave)之后重置。因此,通过再次尝试保存,您指向已消失的文件。

顺便说一句。将当前文档(再次)保存在 PostSave 中(或者就此而言:在 QuerySave 中过早保存)是 Notes 开发中流行的反模式