You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSJS中getCount()显示集合有8个文档,但getFirstDocument()返回null

SSJS集合count显示有文档但getFirstDocument()返回null的排查方案

问题描述

使用SSJS编写代码,通过视图第一列的排序键rstrSerId调用getAllDocumentsByKey获取文档集合,getCount()返回8个文档符合预期,但getFirstDocument()返回null,导致后续文档处理循环无法执行。该代码结构此前已稳定运行数百次,目前无法定位问题。

相关代码

//*---------------------------------------------------------
//* Prime the loop 
//*---------------------------------------------------------
var dcCpt:NotesDocumentCollection = vwCpt.getAllDocumentsByKey(rstrSerId)
if (bfDebug === true) {
    print (strDCon + "Number CptCode .. '" + dcCpt.getCount() + "'")
}   
var docTmp:NotesDocument;
var docCpt:NotesDocument = dcCpt.getFirstDocument();
if (docCpt == null) {   
    print (strDCon + "First Document is 'null' !!!!!")
}           
//*---------------------------------------------------------
//* Process EVERY document
//*---------------------------------------------------------
while (docCpt !== null ){

控制台输出

*** DEBUG *** ssjsAppFunc:getCptItems -  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*** DEBUG *** ssjsAppFunc:getCptItems - STARTING
*** DEBUG *** ssjsAppFunc:getCptItems - rstrSrvId ..... 'SRV-02B57R5P'
*** DEBUG *** ssjsAppFunc:getCptItems - rstrSerId ..... 'SER-09APZJ9A'
*** DEBUG *** ssjsAppFunc:getCptItems - 

*** DEBUG *** ssjsAppFunc:getCptItems - Getting CPT Codes
*** DEBUG *** ssjsAppFunc:getCptItems - Number CptCode .. '8'
*** DEBUG *** ssjsAppFunc:getCptItems - First Document is 'null' !!!!!
*** DEBUG *** ssjsAppFunc:getCptItems - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

排查思路

  • 检查视图索引完整性:视图索引可能损坏或未及时更新。手动刷新视图索引(Domino Designer中打开视图→右键→刷新索引),或重启服务器索引任务;若为按需索引视图,强制触发索引更新。
  • 验证排序键匹配精度:getAllDocumentsByKey默认精确匹配且区分大小写,核对rstrSerId与视图第一列实际存储值的一致性(含大小写、空格、特殊字符)。可尝试getAllDocumentsByKey(rstrSerId, true)开启部分匹配测试,反向验证键的匹配问题。
  • 排查文档权限限制:当前执行代码的用户可能无目标文档的读取权限。用管理员权限用户运行代码,或检查文档读者域是否包含当前用户。
  • 检查文档特殊状态:视图统计的count可能包含软删除、归档或冲突文档,这类文档无法被实际获取。在视图中添加$Conflict、$Revisions等列,查看是否有此类文档被统计在内。
  • 确认对象引用有效性:确保vwCpt视图对象在获取集合后未被提前销毁或重新赋值,避免因视图对象释放导致集合无法访问文档。
  • 尝试替代方法验证:改用vwCpt.createViewNavFromCategory(rstrSerId)获取导航器,再调用getFirstDocument(),判断是集合方法问题还是视图本身问题。
  • 核对Domino版本兼容性:若近期升级了Domino服务器/Designer版本,查看对应版本发行说明,确认getAllDocumentsByKey和getFirstDocument是否有行为变更。

内容的提问来源于stack exchange,提问作者Trevor Denner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 17:27:33