With a lot of help from other Notes developers, I’ve put a button in the inboxes or many users. What it does is defined in the beginning of the code. And it works great. However, we are finding that when users try to use this button with the email still open or in the preview, they get an error message “Cannot remove NotesDocument when instantiated by NotesUIDocument”. We’d like to avoid them getting this error message, by adding script that will save and close the document. I have tried using the Help in Designer, using info on the web, and playing around with it myself. But unfortunately, I am not a developer and VERY new to Lotusscript. Could someone please offer their assistance?Thanks very much in advance. Here is the script minus the walkmime function:
Sub Click(Source As Button)
'Notes Agent: name=ReportAsSpam, trigger=onEvent, Action menu selection, target=All selected docs
'forwards the selected message(s) with full header to a spam reporting email address
'moves message from inbox to trash, refreshes automatically and appends “Spam Submission >” to the subject line
'requires: Function walkmime (mime As notesmimeentity) As String
Const SPAMREPORTADDRESS = "xxx.com" 'the email address used to report spam, uncomment to go live
Const SPAMREPORTADDRESS1 = "yyy.com" 'the email address used to report spam, uncomment to go live
Dim sess As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim memo As NotesDocument, doc As NotesDocument
Dim col As NotesDocumentCollection
Dim mime As NotesMIMEEntity
Dim rtitem As NotesItem
Dim temp As Variant 'to get info from non-ASCII data
Dim i As Integer 'to count messages
Dim uiview As NotesUIView 'to update the inbox after messages have been moved
Dim mail As NotesRichTextItem 'the sent message
Dim item As NotesItem 'to process fields with multiple items (i.e. recieved)
Dim res As Integer
sess.ConvertMime = False 'init mime conversion
Set db = sess.CurrentDatabase
Set col = db.UnprocessedDocuments
Set doc = col.GetFirstDocument()
If doc Is Nothing Then Exit Sub 'sanity check to abort early
Print "Reporting " + Cstr( col.Count ) + " selected documents as Spam to " + SPAMREPORTADDRESS + ". Please wait..."
i = 1
Set col = db.UnprocessedDocuments
If Not col Is Nothing Then
Set doc = col.GetFirstDocument()
If Not doc Is Nothing Then
res = ws.Prompt (PROMPT_YESNO, "Alert", "Are you sure you want to report this email as spam?")
If res =1 Then 'Executes if user select "Yes" to proceed
Else
Exit Sub ' Exists subroutine. Stops execution of code.
End If
While Not(doc Is Nothing)
Set memo = db.CreateDocument
Set mail = New NotesRichTextItem( memo, "Body" )
Set mime = doc.GetMIMEEntity
If Not(mime Is Nothing) Then
Forall header In mime.HeaderObjects
Call mail.AppendText( walkmime ( mime ) ) 'calls required function walkmime
End Forall
Call doc.CloseMIMEEntities 'allow clean switch to using items
If Instr( doc.Subject(0), "SPAM Submission" ) = 0 Then
Call doc.ReplaceItemValue("Subject", "SPAM Submission > " + doc.Subject(0) ) 'remove [spam]
End If
memo.subject = doc.subject(0)
Call memo.Send( False, SPAMREPORTADDRESS) 'forward spam report message
Call memo.Send( False, SPAMREPORTADDRESS1) 'forward spam report message
Print "Successfully reported message " Cstr(i) + " of " + Cstr( col.Count ) +" ("+ doc.Subject(0) + ")"
Else
Print "No MIME content found in message, not sending spam report. (the internet message may have been converted to Notes Format)"
End If
Call doc.Remove(True)
Call ws.ViewRefresh
Call sess.UpdateProcessedDoc( doc )
i = i +1 'increment counter
Wend
Set uiview = ws.CurrentView
Call uiview.DeselectAll 'to prevent UI bugs
sess.ConvertMime = True 'revert mime conversion
Print "Done reporting " + Cstr( col.Count ) + " document(s) as Spam."
End If
End If
End Sub