Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Can I send an email when a document is deleted from LN database?

Posted on 2008-06-13
10
267 Views
Last Modified: 2013-12-18
I would like to send out an email from a lotus notes database when a document is deleted. The email would contain information from the deleted document. I am running Lotus Notes 7.0.2.
0
Comment
Question by:amjava
  • 5
  • 3
  • 2
10 Comments
 
LVL 22

Accepted Solution

by:
mbonaci earned 400 total points
ID: 21779841
Of course you can.
Locate in Designer:
Other - Database Resources - Database Script.

There you have event
Sub Postdocumentdelete(Source As Notesuidatabase).

The sample code is bellow:
	Dim db As Notesdatabase
	Dim doc As NotesDocument, profiledoc As NotesDocument
	Dim c As NotesDocumentCollection
 
	Set db = Source.Database
	Set c = Source.Documents
	
	
	Set doc = c.GetFirstDocument
	Do Until doc Is Nothing		
		'here you handle one by one doc being deleted
		Call SendMail( doc )		'create function that sends mail using values from the doc as information in the mail's subject and body fields.
 
		Set doc = c.GetNextDocument( doc )
	Loop

Open in new window

0
 
LVL 17

Assisted Solution

by:fgrushevsky
fgrushevsky earned 100 total points
ID: 21779911
You also will need to check user access to prevent false emails, as the script is executed even if user does not have enough access to delete documents.

If db.CurrentAccessLevel < 4 Then Continue = False ' user has no access to delete documents

Also, the script will not report on documents that are deleted through domino backend - i.e. if a document was deleted through API application (adminp could be example of that) or a backend agent      
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21779942
And the SendMail sub could be like this:


Sub SendMail( to As Variant, Subject As String, doc As NotesDocument )
	On error Goto ErrHandler
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim rtitem As NotesRichTextItem
	Dim CurrentUser As String
	
	Set db = s.CurrentDatabase
	Set doc = db.CreateDocument
	
	CurrentUser = s.CommonUserName
		
	Set maildoc = New NotesDocument(db) 
	Set rtitem = New NotesRichTextItem(maildoc, "Body")
	Call rtitem.AppendText( "Document " + doc.TheFieldName(0) + " deleted by " + CurrentUser + "." )
	
	maildoc.Form = "Memo"
	Call maildoc.AppendItemValue("SendTo", doc.TheFieldNameInDeletedDoc(0)) 'if the doc holds the intended recipient
	
	maildoc.Subject = Subject
	
	Call maildoc.Send( True )
	
out:
	Exit Function	
ErrHandler:
	Messagebox "SendMail - error: " & Str(Err) & ": " & Error$
	Resume out
End Function

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 22

Expert Comment

by:mbonaci
ID: 21779955
The event is PostDocumentDelete, not QueryDocumentDelete!
So it will execute only after actual deletion of the document.
0
 
LVL 17

Expert Comment

by:fgrushevsky
ID: 21780113
Mbonaci, it does not matter.
PostDocumentDelete script will be executed even if the user does not have rights to delete document (and help warns you about that).
So it will look this way:
user clicks delete key, querydocumentdelete is executed, user clicks F9 to actually delete document, postdocumentdelete is executed, then Notes tells user that user has no rights to delete the document, document stays
0
 
LVL 17

Expert Comment

by:fgrushevsky
ID: 21780212
So you have to check ACL in the script

 db.CurrentAccessLevel is a quick a dirty way,  you would be better using something like this:


accPriv  = db.QueryAccessPrivileges( EffectiveUserName )

If (accPriv And DBACL_DELETE_DOCUMENTS) = 0 Then Continue = False ' user has no access to delete documents

0
 

Author Comment

by:amjava
ID: 21781602
Thanks that looks like it will work great. One last thing can I send the email out based on the form that was used to create it? I only want to send out the email when one certain type of document is deleted from the database.

Thanks
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21783159
Come on, this one you could've done yourself...
        Do Until doc Is Nothing
                If doc.Form(0) = "YourForm" Then
                        'here you handle one by one doc being deleted
                        Call SendMail( doc )
                End if
 
                Set doc = c.GetNextDocument( doc )
        Loop

Open in new window

0
 
LVL 22

Expert Comment

by:mbonaci
ID: 21783260
fgrushevsky you're right, my mistake, it is actually stated in the help of the event that it's triggered before verification of authorization to delete.
(You are welcome to join LinkedIn EE group - see my profile).


So amjava, you're going to need this function:
(Call it from Postdocumentdelete Sub, like this:
        ...
        Dim c As NotesDocumentCollection
 
        'Add these two lines here (or you can change the code to remember that the user can't delete
        'and log unauthorized deletion attempt for each document, or something like that)
        Dim s As New NotesSession
        If Not CanUserDeleteDocument( s.CommonUserName ) Then Exit Sub

        Set db = Source.Database
        ...

Function CanUserDeleteDocument( UserName as String ) As Boolean
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Dim acl As NotesACL
	Dim entry As NotesACLEntry
 
	Set db = s.CurrentDatabase
	Set acl = db.ACL
	Set entry = acl.GetEntry( UserName )
 
	If entry.CanDeleteDocuments Then CanUserDeleteDocument = True
 
'add error handling when you get there...
End Function

Open in new window

0
 

Author Closing Comment

by:amjava
ID: 31466943
Thanks a bunch. Got it working and running just fine. Thanks for the tip on preventing false emails if the user doesn't have access to delete docs!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lotus Domino server 9 7 81
Migration Lotus to Exchange 2016 4 189
@Mailsend 3 66
Split Domain with Lotus Domino and Zimbra mail server. 5 207
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question