我需要检查(在notes客户机中最好是在lotuscript中)是否存在文档,但我不在读者字段中。
Set Doc = view.getdocumentbykey(index) 'returned Doc is nothing
我记得在旧版本的Notes中,我得到一个文档,文档的items属性为nothing(因此没有办法看到项目值,这是逻辑,如果我没有权利看到这个文档)。是否有办法获得这个功能?
如果不是,什么是最好的?
- 在分类视图上评估DBLookUp(如果仍然可以在"不显示空类别未选中…"时这样做)
- 执行代理,代表(签名者将有权读取所有文档)运行,并且仅在文档存在或不存在时返回索引(通过environment notes.ini)
- 在代理服务器上运行(在临时文档中进行大量数据交换)
- json from Notes Client
还有其他想法吗?
为问题添加了一些尝试…
Dim key As String
key = Inputbox("index to search", "" , "123456")
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Set db = session.CurrentDatabase
Set view = db.GetView("ForSearch")
Set nav = view.CreateViewNavFromCategory(key )
If nav Is Nothing Then
MsgBox " nothing for "+ key
Else
MsgBox " nav for " + key +": " & nav.Count
Set entry = nav.Getfirst()
If entry Is Nothing Then
MsgBox "unable to get entry"
Dim vc As NotesViewEntryCollection
Set vc = view.GetAllEntriesByKey(key, False)
If vc Is Nothing Then
MsgBox "unable to getallentries for " + key
Else
MsgBox " vc exists for " + key + " count = " & vc.Count
Set entry = vc.Getfirstentry()
If entry Is Nothing Then
MsgBox "unable to get entry"
Else
MsgBox "entry: " & entry.Columnvalues(1)
End if
End If
Else
MessageBox "Universal ID: " & entry.UniversalID
End If
End If
问题:无法获得所有情况下的条目!因此,我无法确定索引是否存在…注:我在notes客户端中看到了这个类别。
回到@dblookup:
t:=@DbLookup("":"";"":""; "forSearch" ; "123455" ; 2);
@Prompt([ok] ; "123456" ; @If(@IsError(t) ; "ERR:" ; "") + @Text(t) );
这将总是返回一个错误,因此不能用于测试索引是否存在…
t:= @DbColumn("":"" ; "":""; "forSearch" ; 1);
@Prompt([ok] ; "dbcolumn" ; @If(@IsError(t) ; "ERR:" + @Text(t) ; @Contains(t; "123456") ; " @contains is true yep!" ; " inexting index"));
是的,现在我记得这个hack只对@dbcolumn和他的64K限制有效:-(
http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllFlatWeb/4af0288d37df3ade85257c3700779a0e?OpenDocument解释说,在Notes客户端运行代表可能是棘手的(http://www.ns-tech.com/blog/geldred.nsf/plinks/geld-7wmjev非常好的文章),所以…一个解决方案是@formula cascading 3 @Command([ToolsRunMacro];")或runonserver…
在我的具体情况下,这段代码是由一个JS定时器触发的,我不确定调用级联3 @命令将是一个好主意(这意味着在条件未验证时重写公式中的一部分代码到@return(false)…)
从8.5.2版本开始,有可能运行带有内存文档的代理。该方法称为NotesAgent.RunWithDocumentContext(doc As NotesDocument, noteID As String) As Integer
。
你可以在Daniel Nashed的博客中阅读更多内容
与RunOnBehalf结合使用,将是我首选的方法。
一些澄清:对于这种方法,您总是需要两个代理/脚本-部分:
第一个"代码"在用户上下文中运行,可以用LotusScript/XPage JavaScript或Java编写。它创建"内存中"文档,然后调用另一个代理。它的属性是"Run on behalf of"该代理的签名者需要有权代表运行。通常我将代理设置为"Scheduled - Never"
示例代码如下所示:
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim docCache as NotesDocument
Dim ag as NotesAgent
Set db = ses.CurrentDatabase
Set docCache = New NotesDocument ( db )
'- set whatever parameters you want to transmit to the agent
Call docCache.ReplaceItemValue( "MyFirstParameter" , "something" )
Set ag = db.GetAgent( "AgentWithRonOnBehalf" )
Call ag.RunWithDocumentContext( docCache, "" )
'- read return parameter
docExists = docCache.GetItemValue( "docExists" )(0)
在agentwithunonbehalf
Dim ses as New NotesSession
Dim docCache as NotesDocument
Set docCache = ses.DocumentContext
'- read parameters
myParameterValue = docCache.GetItemValue( "MyFirstParameter" )(0)
'- do your search / whatever
....
'- return the result to the calling code
Call docCache.ReplaceItemValue( "docExists", True )
一种方法是使用问题中的代码片段创建调度代理。用Administrator的ID(或可以访问数据库中所有文档的任何ID)对代理签名。如果找到文档,它可以给您发送电子邮件通知,或者它可以创建文档(您有阅读器访问权限),其中包含它找到的文档的详细信息。