Lotusscript forall 循环无法设置变量
Lotusscript forall loop failing to set variable
这可能很简单,但我一直在用头撞墙试图找出我做错了什么。该程序正在读取本地数据库中的一个文档,获取存储在字段中的列表,遍历列表中的每个条目并在另一个数据库的视图中搜索名称,一旦找到它,它就会更新文档并保存它。我看到的问题是 pdoc(下面以粗体显示)永远不会设置为导致程序的其余部分无法更新任何文档的值。
Sub Initialize
Dim db As NotesDatabase
Dim s As New NotesSession
Dim pview As NotesView
Dim ldoc As NotesDocument, pdoc As NotesDocument
Dim lgroup As Variant, pgroup As Variant, errors As Variant
Dim collection As NotesDocumentCollection
Dim nab As New NotesDatabase ("","")
Call nab.Open( "xxxx/xxx", "names.nsf" )
Set db = s.currentdatabase
Set collection = db.unprocesseddocuments
Set ldoc = collection.getfirstdocument
Set pview = nab.GetView ("gfmm")
While Not(ldoc Is Nothing)
On Error Resume Next
lgroup = ldoc.groups(0)
ForAll g In lgroup
**Set pdoc = pview.GetDocumentByKey( g )**
pgroup = pdoc.ListName(0)
If lgroup = pgroup Then
pdoc.GroupType = "0"
Call pdoc.Save(True, True)
Else
errors = errors + g
End If
End ForAll
ldoc.errors = errors
ldoc.status = "Complete"
Call ldoc.save(True, True)
Set ldoc = collection.getnextdocument(ldoc)
Wend
End Sub
错误很简单:lgroups 不是数组而是标量值。这行
lgroup = ldoc.groups(0)
只获取ldoc中项目组的第一个值,而不是所有值。只需将其更改为
lgroup = ldoc.groups
然后你将得到一个可以循环的数组。下面的 pgroup a 视图行也是如此。
这可能很简单,但我一直在用头撞墙试图找出我做错了什么。该程序正在读取本地数据库中的一个文档,获取存储在字段中的列表,遍历列表中的每个条目并在另一个数据库的视图中搜索名称,一旦找到它,它就会更新文档并保存它。我看到的问题是 pdoc(下面以粗体显示)永远不会设置为导致程序的其余部分无法更新任何文档的值。
Sub Initialize
Dim db As NotesDatabase
Dim s As New NotesSession
Dim pview As NotesView
Dim ldoc As NotesDocument, pdoc As NotesDocument
Dim lgroup As Variant, pgroup As Variant, errors As Variant
Dim collection As NotesDocumentCollection
Dim nab As New NotesDatabase ("","")
Call nab.Open( "xxxx/xxx", "names.nsf" )
Set db = s.currentdatabase
Set collection = db.unprocesseddocuments
Set ldoc = collection.getfirstdocument
Set pview = nab.GetView ("gfmm")
While Not(ldoc Is Nothing)
On Error Resume Next
lgroup = ldoc.groups(0)
ForAll g In lgroup
**Set pdoc = pview.GetDocumentByKey( g )**
pgroup = pdoc.ListName(0)
If lgroup = pgroup Then
pdoc.GroupType = "0"
Call pdoc.Save(True, True)
Else
errors = errors + g
End If
End ForAll
ldoc.errors = errors
ldoc.status = "Complete"
Call ldoc.save(True, True)
Set ldoc = collection.getnextdocument(ldoc)
Wend
End Sub
错误很简单:lgroups 不是数组而是标量值。这行
lgroup = ldoc.groups(0)
只获取ldoc中项目组的第一个值,而不是所有值。只需将其更改为
lgroup = ldoc.groups
然后你将得到一个可以循环的数组。下面的 pgroup a 视图行也是如此。