TSO Fong
asked on
(stamp?) Order of merged attachments
Greetings --
In https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=11935798, stamp provided a script that merges attached Word documents into one new Word document from documents selected in a view.
stamp's script begins as follows:
===== BEGIN COPY =====
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim word As Variant
Dim extname As String
Dim i As Integer
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set word = CreateObject("Word.Documen t")
word.Application.Visible = True
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
====== END COPY ======
This works well, except I'm getting complaints about the order in which the documents are merged. The users are assuming (reasonably, I believe) that the Word attachments will be merged in the order they are shown in the view. Instead, they are merged based on the creation dates of the Notes documents that holds the attachments.
I hadn't expected this, but in retrospect I can't say I'm terribly surprised by it either.
Is there any way to get these attachments to merge in the same order they are shown in the view?
Thanks for any assistance.
-- b.r.t.
p.s. -- I'm a script novice, so I'll need any script changes to be fairly specific. I'll add points as appropriate to the difficulty of the answer. Thanks!
In https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=11935798, stamp provided a script that merges attached Word documents into one new Word document from documents selected in a view.
stamp's script begins as follows:
===== BEGIN COPY =====
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim word As Variant
Dim extname As String
Dim i As Integer
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set word = CreateObject("Word.Documen
word.Application.Visible = True
For i = 1 To collection.Count
Set doc = collection.GetNthDocument(
====== END COPY ======
This works well, except I'm getting complaints about the order in which the documents are merged. The users are assuming (reasonably, I believe) that the Word attachments will be merged in the order they are shown in the view. Instead, they are merged based on the creation dates of the Notes documents that holds the attachments.
I hadn't expected this, but in retrospect I can't say I'm terribly surprised by it either.
Is there any way to get these attachments to merge in the same order they are shown in the view?
Thanks for any assistance.
-- b.r.t.
p.s. -- I'm a script novice, so I'll need any script changes to be fairly specific. I'll add points as appropriate to the difficulty of the answer. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Barry,
you are right, but I have tested in $All view, sorted by creation, and this is the default order given by selected colection. So I have not noticed the problem.
There is a hint in NotesHelp, that above of UnprocessedDocuments is possible to get sorted collection with this call:
Set collection = db.UnprocessedFTSearch("?" ,0)
But I have not yet got this collection in any other but creation time order.
Therefore you have two options:
1.) If nomber of document is to huge, and you have a fild in documents as sort criteria, than use above Bubble/Merge sort methods.
2.) If total count of documents in view where you select the document is not to huge, than use my trivial view selection order agent. Example is give in this reduced agent caled: PrintSelectedDocumentsInVi ewOrder
Act on is set to: SelectedDocuments
Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim collection As NotesDocumentCollection
Dim viewdoc As NotesDocument
Dim selecdoc As NotesDocument
Dim i As Integer
Set view = workspace.CurrentView.View
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set viewdoc = view.GetFirstDocument
While Not (viewdoc Is Nothing)
For i = 1 To collection.Count
Set selecdoc = collection.GetNthDocument( i )
If (selecdoc.NoteID = viewdoc.NoteID) Then
Print "Doc(" & i & ") : " & selecdoc.Subject(0)
Exit For
End If
Next
Set viewdoc = view.GetNextDocument( viewdoc )
Wend
End Sub
And the correct URL to the complete old question is here:
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11935798
Have fun,
stamp
you are right, but I have tested in $All view, sorted by creation, and this is the default order given by selected colection. So I have not noticed the problem.
There is a hint in NotesHelp, that above of UnprocessedDocuments is possible to get sorted collection with this call:
Set collection = db.UnprocessedFTSearch("?"
But I have not yet got this collection in any other but creation time order.
Therefore you have two options:
1.) If nomber of document is to huge, and you have a fild in documents as sort criteria, than use above Bubble/Merge sort methods.
2.) If total count of documents in view where you select the document is not to huge, than use my trivial view selection order agent. Example is give in this reduced agent caled: PrintSelectedDocumentsInVi
Act on is set to: SelectedDocuments
Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim collection As NotesDocumentCollection
Dim viewdoc As NotesDocument
Dim selecdoc As NotesDocument
Dim i As Integer
Set view = workspace.CurrentView.View
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set viewdoc = view.GetFirstDocument
While Not (viewdoc Is Nothing)
For i = 1 To collection.Count
Set selecdoc = collection.GetNthDocument(
If (selecdoc.NoteID = viewdoc.NoteID) Then
Print "Doc(" & i & ") : " & selecdoc.Subject(0)
Exit For
End If
Next
Set viewdoc = view.GetNextDocument( viewdoc )
Wend
End Sub
And the correct URL to the complete old question is here:
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11935798
Have fun,
stamp
allow me one word to NotesViewEntryCollection.
As you normaly do, you can compute new values in view colunms with sofisticated formulas. This values are only in the view, not in the document. You get with NotesViewEntryCollection acces to this computed values.
Therefore is this no use for selected documents with attachments.
As you normaly do, you can compute new values in view colunms with sofisticated formulas. This values are only in the view, not in the document. You get with NotesViewEntryCollection acces to this computed values.
Therefore is this no use for selected documents with attachments.
Hello again Barry,
here is an agent working without explicite sorting on every view producing selection in current view order:
Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim position As String
Dim poslist List As Integer
Dim i As Integer
Set view = workspace.CurrentView.View
Set nav = view.CreateViewNav
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
Set entry = nav.GetEntry( doc )
position = entry.GetPosition( "." )
poslist( position ) = i
Next
Forall pos In poslist
Set entry = nav.GetPos( pos , ".")
Set doc = entry.Document
Print "Doc(" & Listtag(pos) & ") : " & doc.Subject(0)
End Forall
End Sub
isn't it nice ;-)
stamp
here is an agent working without explicite sorting on every view producing selection in current view order:
Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Dim position As String
Dim poslist List As Integer
Dim i As Integer
Set view = workspace.CurrentView.View
Set nav = view.CreateViewNav
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
For i = 1 To collection.Count
Set doc = collection.GetNthDocument(
Set entry = nav.GetEntry( doc )
position = entry.GetPosition( "." )
poslist( position ) = i
Next
Forall pos In poslist
Set entry = nav.GetPos( pos , ".")
Set doc = entry.Document
Print "Doc(" & Listtag(pos) & ") : " & doc.Subject(0)
End Forall
End Sub
isn't it nice ;-)
stamp
There comes Stamp, with every other possibilities.
BRT, as you have mentioned you can use NotesViewEntryCollection, I assumed that you had R4. R5 has tremendous capability to do which was considered a limitation in R4.
You can always prompt the user with which view he would use as a template for sorting and from there you can continue.
Good Luck
~Hemanth
BRT, as you have mentioned you can use NotesViewEntryCollection, I assumed that you had R4. R5 has tremendous capability to do which was considered a limitation in R4.
You can always prompt the user with which view he would use as a template for sorting and from there you can continue.
Good Luck
~Hemanth
for heman: Call notesViewEntryCollection.S tampAll(:- ))
nice theory; show me your code...
nice theory; show me your code...
ASKER
HemanthaKumar --
Thanks for the link, HemanthaKumar. I've gone with the sorting method, then merging the attachments from the array rather than from the document collection.
stamp -- Thanks for your input, too. I've chosen not to use your suggestions, but I've still learned from them. Look for another post with some points.
Thanks again to both of you.
-- b.r.t.
Thanks for the link, HemanthaKumar. I've gone with the sorting method, then merging the attachments from the array rather than from the document collection.
stamp -- Thanks for your input, too. I've chosen not to use your suggestions, but I've still learned from them. Look for another post with some points.
Thanks again to both of you.
-- b.r.t.
Barry you do not understand...
usualy I do not look for questions lower the hunder points, because I have no time to explain people the beauty of my solutions (even of this I am #4, actualy).
I am sorry, but this time you have also not seen the value of ViewNavigator solution. Do your bubble sort and in the future, when you play around with Rnext, remeber me and the ViewNavigator code...
Set nav = view.CreateViewNav
Thank you alse for the 25 points offer, but I will not take it.
I hope in your next question I can help you more.
So long,
stamp
usualy I do not look for questions lower the hunder points, because I have no time to explain people the beauty of my solutions (even of this I am #4, actualy).
I am sorry, but this time you have also not seen the value of ViewNavigator solution. Do your bubble sort and in the future, when you play around with Rnext, remeber me and the ViewNavigator code...
Set nav = view.CreateViewNav
Thank you alse for the 25 points offer, but I will not take it.
I hope in your next question I can help you more.
So long,
stamp
ASKER
Thanks for the response.
The question is open to everyone. I put stamp's name there because s/he had helped with the original question.
I've applied the code from the link you provided, and that may be enough for my users. I'll have to wait and see how much they continue to complain.
The trouble is, I have more than two dozen views in this database, as different people in different areas need the records sorted accordingly. The best solution (for me) would be one that merges the documents in the same order they show in the view -- without having to have customized code for each view.
(Each view includes a button that invokes the script in an agent, to make it easier to maintain the code.)
Obviously I could create two dozen different merging agents using different fields as sorting keys for each one. But I don't want to have to maintain that.
Can the above code be made to work with the NotesViewEntryCollection class instead of the NotesDocumentCollection class? I've tried to work with this, but I have very little experience with LotusScript, and I'm not having much success.
Perhaps some hybrid would work, with the NotesViewEntryCollection items (presorted by the view) being fed into the array, rather than dumping the NotesDocumentCollection into the array unsorted and sorting the array.
Thanks for your assistance!
-- b.r.t.