Hi all,
I am trying to pick up the 1st 10 docs. of a collection in a view based on a particular key. I have used an agent for it.The agent is working fine for those keys which have a single doc under them. But I am facing some problems with multiple docs. For ex. the agent is picking the total collection of projects under Sandip(key), but while executing Set ColDoc = collection.GetFirstDocument on that collection, it is surprisingly picking up the 13 th document. I also tried to use “GetnthDocument” along with FTSearch, after creating anew agent. In this case it is giving the same error for multiple docs. & for single doc it is picking an entirely different value. I think this is so because collection creates a sort of its own. I hope some one will be able to help me.
Subject: Doc Collection
Hi Sandip,
From the documentation for a DocumentCollection:
Ordering of documents
The documents in a collection are ordered when the collection results from a full-text search; otherwise, the documents are unordered.
A ViewEntryCollection is sorted. From the documentation for a ViewEntryCollection:
Represents a collection of view entries of type document sorted in view order.
Frunobulax
Subject: RE: Doc Collection
Thank you , its solved.
Subject: RE: Doc Collection
******** GetAllDocumentsByKey **********8Sub Initialize
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Set db = session.CurrentDatabase
Set db = session.CurrentDatabase
Set ProjectView = db.GetView("LUBOwner")
Dim CurValue As Variant
Dim CurValueCost As Variant
Dim Item As NotesItem
Dim CostItem As NotesItem
Dim ChangeFlag As Boolean
ChangeFlag = False
FieldName(0) = "Priority1_Proj"
FieldName(1) = "Priority2_Proj"
FieldName(2) = "Priority3_Proj"
FieldName(3) = "Priority4_Proj"
FieldName(4) = "Priority5_Proj"
FieldName(5) = "Priority6_Proj"
FieldName(6) = "Priority7_Proj"
FieldName(7) = "Priority8_Proj"
FieldName(8) = "Priority9_Proj"
FieldName(9) = "Priority10_Proj"
Set ProjectDoc = ProjectView.GetFirstDocument
While Not (ProjectDoc Is Nothing )
Set n = New NotesName(ProjectDoc.GetItemValue("BusOwner")(0))
key = n.Common
If key <>"" Then
Set collection = ProjectView.GetAllDocumentsByKey(key)
Set TopDoc = db.CreateDocument
TopDoc.form = "TOP_10_Projects"
TopDoc.BusinessOwner = Cstr(ProjectDoc.BusOwner(0))
If collection.Count > 0 Then
Set ColDoc = collection.GetFirstDocument
i = 0
Do Until x = 10
If Not coldoc Is Nothing Then
p= Cstr(ColDoc.Priority(0))
Set item = TopDoc.ReplaceItemValue (FieldName(x) , Cstr(ColDoc.ProjectName(0)))
Set ColDoc = collection.GetNextDocument(ColDoc)
End If
x = x +1
Loop
End If
Call TopDoc.save(True, False)
w = key
End If
key = ""
Set ProjectDoc = ProjectView.GetNextDocument( ProjectDoc )
Wend
End Sub
******** GetnthDocument ************
Sub Initialize
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Set db = session.CurrentDatabase
Set db = session.CurrentDatabase
Set ProjectView = db.GetView("LUBOwner")
Dim CurValue As Variant
Dim CurValueCost As Variant
Dim Item As NotesItem
Dim CostItem As NotesItem
Dim ChangeFlag As Boolean
ChangeFlag = False
FieldName(0) = "Priority1_Proj"
FieldName(1) = "Priority2_Proj"
FieldName(2) = "Priority3_Proj"
FieldName(3) = "Priority4_Proj"
FieldName(4) = "Priority5_Proj"
FieldName(5) = "Priority6_Proj"
FieldName(6) = "Priority7_Proj"
FieldName(7) = "Priority8_Proj"
FieldName(8) = "Priority9_Proj"
FieldName(9) = "Priority10_Proj"
Set ProjectDoc = ProjectView.GetFirstDocument
While Not (ProjectDoc Is Nothing )
Set n1 = New NotesName(ProjectDoc.GetItemValue("BusOwner")(0))
key = n1.Common
If key <>"" Then
count1 = ProjectView.FTSearch( "key", 0 )
Set TopDoc = db.CreateDocument
TopDoc.form = "TOP_10_Projects"
TopDoc.BusinessOwner = Cstr(ProjectDoc.BusOwner(0))
If count1 > 0 Then
i = 0
n =1
Do Until x = 10
Set ColDoc = ProjectView.GetnthDocument(n)
If Not coldoc Is Nothing Then
p= Cstr(ColDoc.Priority(0))
Set item = TopDoc.ReplaceItemValue (FieldName(x) , Cstr(ColDoc.ProjectName(0)))
End If
n = n + 1
x = x +1
Loop
End If
Call TopDoc.save(True, False)
w = key
End If
key = ""
Set ProjectDoc = ProjectView.GetNextDocument( ProjectDoc )
Wend
End Sub