Getting a value from Embedded View in Lotus Notes - 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.

Related

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 :)

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;

Searching Lotus Notes Databases

I have around 50 lotus notes databases which I need to search through (including RTFs and attachments) based on a rather complicated query (for example: If customer = a or b or c or d or e ... or z & product = x or y) then == match; and a tag to (e.g. tag = found or not found)
However, I wasn't sure the best way to go about this and wanted to check three options.
Using Lotus' 'Search in View' should, after indexing, search all the databases - however I am unsure if it will accept a long, complicated search query
Coding an agent in Lotus SCRIPT to basically perform the search in 1. but this might be a way of getting it to accept a complicated query
Using external software (e.g. X1 Professional Search) to search outside of Lotus Notes (however I am not sure if I will be able to tag the files if I identify them in windows explorer).
Edit: My idea is:
Sub Initialise
Dim session as New NotesSession
Dim db as NotesDatabase
Dim dc as NotesDocumentCollection
Dim doc as NotesDocument
Dim searcy_query$
'On current database
Set db = session.CurrentDatabase
'Force index of database
Call db.UpdateFTIndex(True)
'Construct QUERY
search_query = "(Customer1|Customer2) & (Product1|Product2)"
'Search
Set dc = db.FTSearch(query, 0)
If dc.Count=0 Then
Msgbox "No matches!"
Exit Sub
End If
‘Tag the matched documents with “Flag”
Call dc.StampAll("Flag","Active)")
End Sub
However, I am not sure if this will return all matches and also regarding #TRIM and #UPPER (where to put them into the query as I will be searching all fields and RTFs rather than specific ones)
First of all: Searching more than one database at a time can of course be done "manually" by searching each individual database, collection the results and find a way to present the documents "somehow" (what will not be easy, as documents from different databases cannot be shown in "one" view - you would need to use "shadow- documents" or a web- approach (e.g. XPages))
BUT: Lotus Notes has a built-in function to do this, it is called "Domain Indexer". You can read more about how to setup "domain index" in this IBM Link or in your administration help.
Examples for using the domain- index for multi- database- searches can be found in catalog.nsf in the form "DomainQuery".
The search- string does not have a limit as far as I know, so that you can do very complex searches with this technique and it gives you all the matches.
If you search for a LotusScript- Solution, check the documentation for NotesDatabase.ftdomainsearch for example code like this (taken from developer help):
The following code, when placed in a button on a search form within a directory catalog database, searches the directory for the specified query string, and returns all results.
Sub Click(Source As Button)
Dim s As New NotesSession
Dim db As NotesDatabase
Dim w As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc as NotesDocument
Dim quer As String
Dim srdoc as NotesDocument
Set db=s.CurrentDatabase
Set uidoc = w.currentdocument
uidoc.refresh
Set doc=uidoc.Document
quer=doc.query(0)
On Error Resume Next
If db.isopen Then
If Err <> 0 Then
Messagebox STR_DBOPEN_ERROR, 0 , STR_ERROR
Err = 0
Exit Sub
End If
Set srdoc = db.ftdomainsearch(quer, 0)
If Err <> 0 Then
Messagebox STR_NDF , 0 , STR_LOTUS_NOTES
Err=0
Exit Sub
End If
srdoc.Form="SearchResults"
Call w.EditDocument(False, srdoc, True)
End If
End Sub
If you also intend to search Rich Text, the simplier way is Full Text Search, you got the point!
The syntax for your query is:
generic_text or ([_CreationDate]<07.10.2014 and ([CustomerFieldName]="Smith" or [CustomerFieldName]="Wesson"))
For formating the Result, I'ld suggest looking at:AppendDocLink for something like:
Dim session As New NotesSession
Dim db As New NotesDatabase("", "resu.nsf")
Dim newDoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Set newDoc = New NotesDocument( db )
Set rtitem = New NotesRichTextItem( newDoc, "Body" )
'you have to loop on your 50 DBs
'Search =>from your code
Set dc = db.FTSearch(query, 0)
while not doc is nothing
Call rtitem.AppendDocLink( doc, db.Title )
Call rtitem.AddTab( 1 )
Call rtitem.AppendText( doc.FieldImportantInResult( 0 ) )
Call rtitem.AddNewLine( 1 )
Set doc = dc.GetNextDocument( doc )
Wend
newDoc.save true, true
'this part is not to add it you plane to run your search in background
Dim w As New NotesUIWorkspace
Call w.EditDocument(False, newDoc, True)

Set uidoc = workspace.CurrentDocument crash

I try to create pdf file with NotesDocumentCollection(a collection) or a notesuidocument
problem - When i try with a base with NotesDocumentCollection, it
works to create a pdf in the document but i can't extract them... i
can't see
problem - when i try with a base with notesuidocument : it's crash
!!
I want to use the same code with the two type of base...
This is my code :
Public Sub sauverPdfPiecesJointes
Dim s As NotesSession
Dim db As NotesDatabase
Dim colldoc As NotesDocumentCollection
Dim doc As NotesDocument
Dim resultat As String
Dim monRepertoire As Repertoire
Dim monXml As Xml
Dim fichierExiste As Integer
Dim i As Integer
Dim uidoc As NotesUIDocument
Dim workspace As New NotesUIWorkspace
Dim flagUidoc As Integer
Dim nb As String
Dim vue As NotesView
Set s = New NotesSession()
'initialisation de la variable
totalResultat = ""
Set db = s.CurrentDatabase
dbFilePath = db.FilePath
dbFileName = db.FileName
'initialisation du compteur
i = 0
flagUidoc = 0
'creation du pdf du document
Set uidoc = workspace.CurrentDocument <==== CRASH HERE
Set colldoc = db.UnprocessedDocuments
If (uidoc Is Nothing) Then
'plusieurs documents sont sélectionnés
If (colldoc.Count > 0) Then
Set doc = colldoc.GetFirstDocument
While Not doc Is Nothing
(creation du pdf....) (...)
i = i + 1
Set doc = colldoc.GetNextDocument(doc)
Wend
End If
' l'utilisateur est dans le document
Else
flagUidoc = 1
'si l'utilisateur a fait une modification
Set doc = uidoc.Document
nb = doc.Universalid
Call uidoc.Close(true)
Delete uidoc
Set doc = db.Getdocumentbyunid(nb)
(creation du pdf....) (...)
Set vue = db.Getview(nomVue)
Call vue.Refresh()
End If
I will update the question if you post more details based on this answer.
Go to your IBM_TECHNICAL_SUPPORT folder and find the latest NSD.
Open it and look for the word FATAL. This will give you the crash stack. Add that to your question and it will give more details.
To understand in more detail there is a wiki article explains how to determine crashing code (although you are pointing to it, frontEnd classes don't aways behave how you expect them).
As for NotesUIWorkspace. There were issues in earlier versions of Notes (I think R8.0, or possibly R7). The issue was if you opened a Notes client but didn't open a database before executing the code, the NotesUIWorkspace would not initialise fully. It's a edge case, so not obvious.
You can also try using other methods on the NotesUIWorkspace object before touching the document. See if it crashes as well.
Other then this, for your code to work it also needs to have a document in context in the front end. So if you have not selected a document, or have a document open then it should fail (but not crash).
You can also use the LND tool to get more details on the nature of the crash.
After analyzing your code I assume that
it is an agent
with target option "All selected documents" and
shall work on current opened document or on selected documents in view
The usual pattern for this kind of jobs is to look
first for selected documents in view with database.UnprocessedDocuments and if no documents are selected
second for opened document in UI or for marked document in view with session.DocumentContext
This way you don't need a NotesUIDocument and with following code example you have to call your pdf creation code only once:
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
If col Is Nothing Then
Set doc = session.DocumentContext
Else
Set doc = col.GetFirstDocument
End If
While Not doc Is Nothing
'
' create pdf for doc here ....
'
If col Is Nothing Then
Set doc = nothing
else
Set doc = col.GetNextDocument(doc)
End If
Wend

Lotus notes - refering to a doc. from a NotesDocumentCollection

I have a view which on top there is a button called Delete
I want to delete all the selected documents from the view; for this I used:
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim database As NotesDatabase
Dim documentCollection As NotesDocumentCollection
Set database=session.CurrentDatabase
Set documentCollection=database.UnprocessedDocuments
If documentCollection.Count=0 Then
Msgbox "No documents selected ",,"warning"
Else
userChoice=Msgbox ("Delete" & Cstr(documentCollection.Count) & " documents?",64+100, _
"Confirm...")
If userChoice=6 Then
Call documentCollection.RemoveAll(True)
Call workspace.ViewRefresh
End if
But, what if I want to delete only some docs ( from all selected docs. from view ) which have let say Value = YES where Value is a text field inside the document?
I tried declaring:
Dim ui As NotesUIDocument
Dim doc As NotesDocument
Set doc=ui.document
But I get the message: Object variable not set. So I guess I have to refer to a document using the NotesDocumentCollection? How?
Thanks for your time!
Your Error Message has nothing to do with your question... The Error Message comes from setting doc form an unitialized uidoc. You need to have a Set ui = ws.CurrentDocumentsomewhere in your code, and of course declare ws: Dim ws as New NotesUIWorkspace
But for your question you don't need an ui- document at all. To delete just some of the selected documents, you cycle through the collection and delete just the documents that match your criteria:
Dim doc as NotesDocument
Dim nextDoc as NotesDocument
Set doc = documentCollection.GetFirstDocument()
While not doc is Nothing
Set nextDoc = documentCollection.GetNextDocument(doc)
if doc.GetItemValue( "Value" )(0) = "Yes" then
call doc.Remove(True)
end if
Set doc = nextDoc
Wend
Or you reduce the collection to just contain the documents that match your criteria and then delete the whole collection:
Call documentCollection.FTSearch("[Value] = Yes",0)
Call documentCollection.RemoveAll()
But take care: The collection is reduced with a FTSearch, that might also get "Yes of course" or "Ye" depending on the setting of the FT Index of the database -> Not very reliable.
You need to loop through the documents in the document collection and then process them individually. Here's an example loop that uses your documentCollection variable:
Dim doc As NotesDocument
Set doc = documentCollection.GetFirstDocument
While Not(doc Is Nothing)
' Do stuff
' Get next document
Set doc = documentCollection.GetNextDocument(doc)
Wend

Resources