Das Notes Forum
Lotus Notes / Domino Sonstiges => Tipps und Tricks => Thema gestartet von: Rob Green am 13.03.03 - 18:22:43
-
ins QUERY OPEN schmeissen:
IF Bedingung Then
noteid$ = source.document.NoteID
Delete source '[ this deletes the memory reference to the uidoc and anything inferred from it, except noteid$ lingers on ]
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 If
Was daran so besonders ist?
Wenn ein bestehendes Doc im Frontend aufgerufen wird, kann man normalerweise per "doc.remove" Anweisung das aktuelle Dokument nicht entfernen, weil es im Backend über das Frontend initialisiert worden ist und damit jeglicher Löschversuch per Backend Methode über die Fehler-Meldung "...Backend Doc is already instantiated in NotesUIDocument..." unterbunden wird.
Mit dem obigen "Trick" schafft man es dennoch. Dazu beim Verlassen des Doc zB im QuerySave ein Flag setzen und dieses Flag im QueryClose abfragen...sonst würde ja jedes Doc gelöscht werden und das wäre nit so dolle.
öhm ... ja.. peinlich... die Quelle ist das LDD Forum für R4/5, doch finde ich es nicht mehr...der Autor hieß irgendwas mit "Tom..."
-
Hi
Verwende folgenden Script:
' UI Dokument schließen und altes Dokument löschen
Call old_uidoc.close
old_unid = old_doc.UniversalID
Delete old_uidoc
Set old_doc = session.CurrentDatabase.getDocumentByUNID(old_unid)
If Not(old_doc Is Nothing) Then
Call old_doc.remove(True)
End If
Die Variablen müssen entprechend deiner Anwendung geändert werden.
Gruss
Poly
-
oder so..danke :)
-
Hi,
danke!!!!! :D
Hab mich soeben ca. 1,5 Stunden mit Front- und Backend beschäftigt und mit Löschen eines geöffneten Doks per Button. Dann hab ich via Suche diesen Thread gefunden.
Hab jetzt den Code von Poly genommen, er funzt einwandfrei!!!
Hier bei Bedarf der komplette copy&paste - fähige Code:
Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim old_uidoc As NotesUIDocument
Dim old_doc As NotesDocument
Set db = session.CurrentDatabase
Set old_uidoc = workspace.CurrentDocument
Set old_doc = old_uidoc.document
Call old_uidoc.close
old_unid = old_doc.UniversalID
Delete old_uidoc
Set old_doc = db.getDocumentByUNID(old_unid)
If Not(old_doc Is Nothing) Then
Call old_doc.remove(True)
Call workspace.viewrefresh()
End If
End Sub
bye,
Bob
P.S:
Die R5 Designerhilfe gibt zwar dazu auch ein Codebeispiel, aber es funkioniert bei mir definitiv nicht:
3.This script gets the universal ID of the current UI document, marks the document for deletion and closes it. The script then retrieves the back-end NotesDocument object from the database and removes it with the NotesDocument Remove method.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim docA As NotesDocument
Dim s As String
Set db = session.CurrentDatabase
Set uidoc = workspace.CurrentDocument
Set docA = uidoc.document
s = docA.UniversalID
Call uidoc.deletedocument()
Set docB = db.getDocumentByUNID(s)
Call docB.Remove(True)
Call workspace.viewrefresh()