hi all,
I have an embedded view with show single category, with an action button that when click, the highlighted document will be removed from the embedded view, my problem is that the users should not have delete rights, so what I did is to change the field value of the selected document that so that it will not be included in the embedded view. however, when I call the uidoc.Refresh the Notes will crash down.
any other way in doing this? thanks
Subject: removing selected document from embedded view
Hi there…
If your document is open in read-mode then uidoc.Refresh will not work.
I usually do this:
-
Get the embedded view from backend (NotesDatabase.GetView)
-
Refresh this (NotesView.Refresh)
-
Refresh the client (NotesUIWorkspace.ViewRefresh)
In odd situations you have to repeat the refresh part twice.
This solution can be used in both edit- and read-mode. In edit-mode you can add this line between NotesView.Refresh and NotesUIWorkspace.ViewRefresh:
If uidoc.EditMode then uidoc.Refresh
Danish regards,
Christopher P. Winkel
Subject: removing selected document from embedded view
Second response 
Are you sure you have the correct document selected ? As in:
- You might have a document in the embedded view selected
or
- You might have the “main” document selected (the one containing the embedded view)
I always use a NotesUIWorkspace.PickListCollection when I wan’t to delete (or soft-delete) documents from an embedded view.
Example:
Danish regards,
Christopher P. Winkel
Subject: RE: removing selected document from embedded view
thanks for the response chris, but when I add the code uidoc.Refresh, the notes will crash. but when I manually refresh the document (F9) without using uidoc.Refresh it works fine. Is their something I am missing here?
Subject: RE: removing selected document from embedded view
Hi again…
Try putting in some Messagebox lines to debug your code (or use the built-in debugger).
You could try these lines:
Messagebox "Uidoc form: " + uidoc.Document.Form(0)
Messagebox "Selected form: " + doc.Form(0)
(insert these before you delete the document)
What I’m trying to find out is wether or not you are trying to delete the selected document or the main document. If both messageboxes give the same result then you are deleting the wrong document.
You could also copy/paste your code here. Maybe I (or others) can spot an error.
/Chris
Subject: RE: removing selected document from embedded view
actually i’m not deleting the document, I’m just changing the field that is used in the show single category so that useres without delete rights can still remove documents from the embedded view. below is the code.
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim view As NotesView
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim agent As NotesAgent
Set db = session.CurrentDatabase
Dim uidoc As NotesUIDocument
Set uidoc = Workspace.CurrentDocument
Dim col As NotesDocumentCollection
Set col = db.UnprocessedDocuments
Set doc = col.GetFirstDocument
'Make sure there is a highlighted document iin the embedded view
If doc Is Nothing Then
Messagebox "Please select a document to remove.",,"Nothing Selected"
Exit Sub
End If
doc.uniqueid=""
Call doc.Save(True, False)
Set col = Nothing
Set doc = Nothing
Set view = db.GetView("docz")
Call view.Refresh
Call uidoc.Refresh
'docz is the name of the embedded view
'when this code executes the line uidoc.Refresh the Notes Client will hang
Subject: RE: removing selected document from embedded view
Hi again…
Try using this code in the end:
Call doc.ReplaceItemValue(“uniqueid”, “”)
Call doc.Save(True, False, True) 'I don’t like the “unread” mark (see the help file on NotesDocument.Save)
Set col = Nothing
Set doc = Nothing
Set view = db.GetView(“docz”)
view.Refresh
If uidoc.EditMode then Call uidoc.Refresh
workspace .ViewRefresh
view.Refresh
If uidoc.EditMode then Call uidoc.Refresh
workspace .ViewRefresh
'Yes… Im refreshing the view/uidoc/workspace twice (due to a problem I have had with Notes 7.0.2)
If this doesn’t work then I’ll post the code for a different way of doing this.
/Chris
Subject: RE: removing selected document from embedded view
hi Chris,
still this doesn’t work, my notes client will still crash when executing the uidoc.Refresh. I’m using R6.5 can you suggest any other way? thanks
Subject: RE: removing selected document from embedded view
Try this code then(notice the first “Note” comment where you probably have to change the code)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim view As NotesView
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim agent As NotesAgent
Set db = session.CurrentDatabase
Dim uidoc As NotesUIDocument
Dim maindoc As NotesDocument
Set uidoc = Workspace.CurrentDocument
Set maindoc = uidoc.Document
Dim col As NotesDocumentCollection
Set view = db.GetView("docz")
Call view.Refresh
Set col = workspace.PickListCollection(1, False, db.Server, db.FilePath, "docz", "Delete document", "Please select a document for deletion", maindoc.uniqueid(0))
'Note: maindoc.uniqueid(0) is the field value from the maindoc you use for “Show single category” on the embedded view
If col Is Nothing Then Exit Sub
Set doc = col.GetFirstDocument
If doc Is Nothing Then Exit Sub
Call doc.ReplaceItemValue("uniqueid", "")
'Note: I assume this is enough to remove the sub-document from the embedded view
Call doc.Save(True, False, True)
view.Refresh
If uidoc.EditMode Then uidoc.Refresh
workspace.ViewRefresh
view.Refresh
If uidoc.EditMode Then uidoc.Refresh
workspace.ViewRefresh
Subject: RE: removing selected document from embedded view
Hi Chris,
Your code works fine.
Thank you very much, you’re the man
Subject: RE: removing selected document from embedded view
Hi Chris,
This code only works when the document (uidoc was already save, not new doc) but when uidoc is newdoc then my Notes Client still crashes.
Do you have any idea what is happening?
Thanks
Subject: RE: removing selected document from embedded view
Hi again…
When working with documents it is a good idea to make sure they’re saved.
You can start off the code with:
if uidoc.IsNewDoc then uidoc.Save
or even better:
if uidoc.EditMode then uidoc.Save
Or if you know exactly what line(s) causes the crash then you can do something like:
If not(uidoc.IsNewDoc) then
Example:
If not(uidoc.IsNewDoc) then
If uidoc.EditMode Then uidoc.Refresh
End if
Personally I always make sure my uidoc is saved when I add or remove sub-documents. I do something like:
-
If the document is in edit-mode then
-
Check if all mandatory fields contains the correct values. Then
-
uidoc.Save and
-
Add/remove/edit sub-documents
/Chris