How can I delete a current document and close the window in an action button?

本秂侑毒 提交于 2021-02-11 06:42:29

问题


I changed an action button 'into', so when some user press this button I just save the Uidoc. I would like to delete this document considering the fact that if I do not delete it all documents will be saved on ALLdocument views!

When I try to delete the document (call doc.remove) i receive the error message: "Cannot remove notesdocument when instantiated by NotesUIDocument", all this in another action button of the doc.

Also, I would like to close the NotesDocument. I also tried something like:

@Command([movetotrash]);
@Command([emptytrash]);
@Command([fileclosewindow]) but it doesn;t work. Thank you, Samir Akhtubir

I tried smth like this, too:

 Sub Queryclose(Source As Notesuidocument, Continue As Variant)
   noteid$ = source.document.NoteID
   Delete source 
   Dim S As New notessession
   Dim db As notesdatabase
   Set db = s. currentdatabase
   Dim doc As Notesdocument
   Set doc = db.GetDocumentbyID(noteid$)
   Call doc.Remove(True)
 End Sub

But if I put this code into the doc that has just been created, all the docs will be deleted. Then I putted into the QueryClose of my action button called 'Cancel' but it isn't working.

So, how can I delete a current document and close the window in an action button?


回答1:


Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc as NotesDocument

'*** Get currently open document
Set uidoc = ws.CurrentDocument
'*** Save it, so we can later close it
'*** without prompt. You can also set
'*** the field SaveOptions to "0".
Call uidoc.Save()
Call uidoc.FieldSetText("SaveOptions","0")
'*** Get the backend document
Set doc = uidoc.Document
'*** Force closed the UI document
Call uidoc.Close(True)
'*** Delete the backend document
Call doc.Remove(True)

If that does not work, set a delete flag on the document. I normally use 'flagDelete' and set it to "Yes". I have all my views filtered to not display any documents with this field set to "Yes". I then have a scheduled agent that will delete all documents with 'flagDelete' set to "Yes" once an hour, or once a day (depending on how many documents are processed per day).

That method has another advantage. You can remove delete access from the ACL, but still allow users to "delete" specific documents by setting the flag. Then the documents are deleted for real by the scheduled agent, running with delete access. Of course, any code you have that perform searches or other lookups not based on views, must be modified to exclude the documents as well.



来源:https://stackoverflow.com/questions/12634866/how-can-i-delete-a-current-document-and-close-the-window-in-an-action-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!