Lotus Notes UnprocessedDocuments on embedded view - lotus-notes

i have a doc with embedded view... in this embedded view i have a button that compile some code.
Inside this code i have Set Coll=db.unprocesseddocuments instructioin so when i select document inside this embedded view i think the collecion is composed by the document that i have select.
But the collecion contains the current uiwork documents instead the document that i have select inside the embedded view. Why ? How can i populate the collection with the selected document of the embedded view ?
With #command([toolsrunmancro];"MyAgent") instead the simply code inside the button the result is the same...
Someone can help me ?

This example works for me:
Action button "Test" in view (LotusScript)
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set col = db.UnprocessedDocuments
Set doc = col.GetFirstDocument
While Not doc Is Nothing
Print doc.UniversalID
Set doc = col.GetNextDocument(doc)
Wend
End Sub
The Embedded View properties are
After selecting documents in embedded view a click on action button "Test" prints all selected documents Universal ids.

I think the key to Knut's answer is that the button in question must be an action button within the embedded view, and not a button on the form.

Related

Click button to copy document to another view

I have two views which are Computer and Draft. I create a button in computer view and it is to create a copy of computer document to draft view.
Below is my button code. When I click the button, it said "Object variable not set"
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim view As NotesView
Set db = session.CurrentDatabase
Set view = db.GetView( "Draft" )
Set doc = dc.GetFirstDocument()
Set dc = db.AllDocuments
While Not (doc Is Nothing)
Call doc.CopyToDatabase(db)
Set doc = dc.GetNextDocument(doc)
Wend
End Sub
Can anyone help me? And can I ask, do I need to insert any formula inside Draft view? Thanks for any help!
Update Question
I have found the problem and fixed my code. But when I click the button, it copies all document and shows on both views. How can I want a copy of the document in Draft only selected document? For example, the "Active" document only? Thanks!
Views do not "contain" documents. Documents are in a database, and views show selected documents, using a SELECT formula. If your SELECT matches all documents, all documents will show up. That formula decides which documents are part of the view.
If view A contains your document and view B doesn't, you have to adapt the SELECT formula in view B so that it will match the document.
E.g. if you want your current document to show up in view B, you could add a value to the current document, like DocumentViews, and set it to "B", and set the SELECT formula of view B to SELECT DocumentViews="B".
Now, if you want to do something with the document that's currently selected in a view, you can use the NotesDatabase.UnprocessedDocuments property. It contains a list of all selected documents.
Dim ns As New NotesSession
Dim db As NotesDatabase
Set db= ns.CurrentDatabase
Dim dc As NotesDocumentCollection
Set dc= db.UnprocessedDocuments
Dim doc As NotesDocument
Set doc= dc.GetFirstDocument
Dim newdoc As NotesDocument
Do Until doc Is Nothing
' you might have to check the status of the current document before copying...
Set newdoc= doc.CopyToDatabase(db)
Call newdoc.ReplaceItemValue("Status", "Draft")
Call newdoc.Save(True, False)
Set doc= dc.GetNextDocument(doc)
Loop

How to access lotusscript variable in button action formula?

In a view I have created a checkbox action button. The action button shows/hides the checkbox based on the formula I have set:
#If( AAAR = True; #True; #False )
I declared the variable AAAR under the view's declaration section like this:
Dim AAAR As Boolean
Now this flag is set in the OnSelect event so that whenever users clicks/selects a document from the view, this event triggers:
Sub Onselect(Source As Notesuiview)
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim uiview As NotesUIView
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set uiview = ws.CurrentView
Set doc = db.GetDocumentByID(uiview.CaretNoteID)
If doc.GetItemValue("AllotmentApprovalReq")(0) = "Yes" Then
AAAR = True
Else
AAAR = False
End If
End Sub
Now the problem is that, i want the checkbox menu should change its status (checkbox / no checkbox) based on this value AAAR. I have to do 'something' in
the OnSelect event but i don't know how to access and set the checkbox menu from there. Please help.
Wow, this is a total mess: First of all: #Formulas variables and LotusScript- Variables have nothing to do with each other. In #Formula whenever you write a variable name it is always one of the following two:
An item with that name in the document that is currently in focus (an open document or the document under the cursor in a view). Beware: Actions are NOT automatically recalulated when you select another document, you need to enable the action bar properties of the view to update on focus change
A variable from earlier in the same formula
If your example is right, then the formula in your action button would simply be:
#If( AllotmentApprovalReq = "Yes"; #True; #False )
No need of any code in Onselect at all...
But again: You need to set the view action bar to recalculate on every focus change.

Lotus Notes - exclude current document from embedded view

I have an embedded view from which I would like to exclude the current document. Is there a way of doing this? The view selection is correct and displays a number of documents which include the document which contains the embedded view (which I would like to exclude).
In my opinion you have no chance to exclude the current document from your embedded view because the only choice you have is to show a single category in an embedded view.
A workaround could be to prevent the current document from opening:
Sub Queryopendocument(Source As Notesuiview, Continue As Variant)
Dim docs As NotesDocumentCollection
Dim doc As NotesDocument
Set docs = Source.Documents
Set doc = docs.GetFirstDocument
Dim ws As New NotesUIWorkspace
If doc.UniversalID = ws.CurrentDocument.Document.UniversalID Then
Continue = False
End If
End Sub
I hope this helps :)

Getting a value from Embedded View in Lotus Notes

I have probably a very simple problem but got stuck on it
I have a form inside it i have a field and for it i want to take value from a embedded view has anybody a idea how to accomplish it.
Getting a value from an embedded view from the "surrounding" document is not possible. But the opposite direction definitely is.
In the code of all events / actions in the embedded view you can use the following code to get the surrounding document:
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Then you could set fields on base of the currently selected document in the view e.g. in the event Onselect (new since Version 8) you could place some code like this (partly taken from Desiger help of event Onselect ):
Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument
Dim lastCaretID As Variant
lastCaretID = "000"
Set uidoc = ws.CurrentDocument
Sub Onselect(Source As Notesuiview)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Set db = session.CurrentDatabase
caretNoteID$ = Source.CaretNoteID
If lastCaretID <> caretNoteID$ Then ' we only process if the highlighted row has changed
lastCaretID = caretNoteID$
noteID$ = "NT00000" + caretNoteID$
Set doc = db.GetDocumentByID( caretNoteID$ )
Call uidoc.Document.ReplaceItemValue( "SelectedSubject", doc.GetitemValue( "Subject") )
End If
End Sub
Take care: Calling uidoc.Refresh / uidoc.Reload from within code in the embedded view context will most certainly crash your Notes- Client, so don#t do this...
As far as I know there is no easy way to do that in classic Notes. You may have to rethink your design/approach. I would use a picklist dialog box for this.
I am sure you can do that in XPages, or if this is a web application it would not be that difficult to do with Javascript/jQuery.

Refresh lotus documents with scheduled agent

I have an error on a computed for display text field.
For Each document, i open it in edit mode and resave to correct it.
I have the same problem on many databases and documents.
I tried to correct it with an agent over the entire base with the function EditDocument in uiworkspace . As follows:
Option Public
Option Declare
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim view As NotesView
Dim doccand As NotesDocument
Dim doc As NotesDocument
Dim result As Integer
Dim uiwks As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set db = session.Currentdatabase
Set col = db.Unprocesseddocuments
Set docCand = col.getfirstdocument
On Error Resume next
While Not docCand Is Nothing
Set uidoc = uiwks.Editdocument(True, docCand)
Call uidoc.save
Call uidoc.close(True)
Set docCand = view.getNextdocument(docCand)
Wend
End Sub
This function corrects the problem only when I start it from my Notes client. It does not work as a scheduled task in the domino server. I tried with computewithform without uiworkspace and it does not work either.
Anyone have a method to refresh with edit and save document in scheduled agent?
computed for display text field
Such type of fields are not saved in documents, it's kind of same thing as a Computed Text.
About your solution:
NotesUIWorkspace and EditDocument can't be use in a schedule agents that run in background (i.e. on server)but only from UI (that's why it works when you run LN).
What you need to do is to use ComputeWithForm method from NotesDocument. It will refresh documents in background (no need to open/save it).
While Not docCand Is Nothing
Call docCand.ComputeWithForm(False, False)
Call docCand.save
Set docCand = col.getNextdocument(docCand)
Wend
Notice, in your script there is an issue, you are trying to get next document from a view which is not initialized. I guess you want to use col instead.
Set docCand = view.getNextdocument(docCand)
Computed for display fields are not supposed to be saved. You should not have to do a refresh.
There is only one circumstance that I know of in which the value of a computed for display field is saved. It happens when the field on the form is originally designed as a regular computed field, but then someone changes it to computed for display. The original computed fields were saved as items in the stored document, and even after the field is changed to computed for composed Notes will continue to see the saved value. If that's what's happening, then what you really want to do is run an agent to delete the saved values. E.g.,
FIELD myFieldThatUsedToBeComputedButIsNowCFD := #DeleteField;

Resources