miklesw
asked on
Reply without attachments in R5
I have found this peice of code to add to the postopen event of the reply with history form.
It works fine but it has one major fault. It saves the document in order to access the rich text item, resulting in a draft, which remains there when memo is discarded .(Another weakness is that the attachment is removed after loading the reply, but i can live with that)
Is there another alternative to this approach or a way to avoid saving?
I know R6 has this, we're upgrading the templates in 4 months. But you know how bigshots are once they get something in their head.
Sub Postopen(Source As Notesuidocument)
Call cMemoObject.PostOpen(Sourc e)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim doc As NotesDocument
Dim id As String
id = session.GetEnvironmentStri ng("Delete Attachment ")
If id <> "" Then
On Error Goto finish
Set doc = db.GetDocumentByUNID(id)
If Not doc Is Nothing Then
Call doc.Remove(True)
End If
Call session.SetEnvironmentVar( "DeleteAtt achment", "")
End If
finish:
'Remove attachments - if any
Set doc = Source.Document
If doc.HasEmbedded <> True Then
'No attachments
Exit Sub
Else
If Msgbox("Do you want to keep the attachments in this Memo?",4+32+4096,"Reply with History") = 6 Then
Exit Sub
End If
End If
'Here we remove attachments
'Call Source.Save
Dim item As NotesRichTextItem
Set item = doc.getFirstItem("Body")
Msgbox "got body"
'Set item = source.Body
Forall o In item.EmbeddedObjects
Msgbox "looking for att"
If (o.Type = EMBED_ATTACHMENT) Then
'And write the name on the removed files
Msgbox "found att"
Call item.Appendtext("<< Attachment removed : " + o.Source + " >>")
Call item.AddNewLine(1)
Call o.Remove
Msgbox "removed att"
Call doc.Save(1,0,1)
Msgbox "save"
End If
End Forall
Call Source.Close
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.EditDocument(Tru e, doc)
Call session.SetEnvironmentVar( "DeleteAtt achment", doc.UniversalID, False)
Exit Sub
End Sub
It works fine but it has one major fault. It saves the document in order to access the rich text item, resulting in a draft, which remains there when memo is discarded .(Another weakness is that the attachment is removed after loading the reply, but i can live with that)
Is there another alternative to this approach or a way to avoid saving?
I know R6 has this, we're upgrading the templates in 4 months. But you know how bigshots are once they get something in their head.
Sub Postopen(Source As Notesuidocument)
Call cMemoObject.PostOpen(Sourc
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim doc As NotesDocument
Dim id As String
id = session.GetEnvironmentStri
If id <> "" Then
On Error Goto finish
Set doc = db.GetDocumentByUNID(id)
If Not doc Is Nothing Then
Call doc.Remove(True)
End If
Call session.SetEnvironmentVar(
End If
finish:
'Remove attachments - if any
Set doc = Source.Document
If doc.HasEmbedded <> True Then
'No attachments
Exit Sub
Else
If Msgbox("Do you want to keep the attachments in this Memo?",4+32+4096,"Reply with History") = 6 Then
Exit Sub
End If
End If
'Here we remove attachments
'Call Source.Save
Dim item As NotesRichTextItem
Set item = doc.getFirstItem("Body")
Msgbox "got body"
'Set item = source.Body
Forall o In item.EmbeddedObjects
Msgbox "looking for att"
If (o.Type = EMBED_ATTACHMENT) Then
'And write the name on the removed files
Msgbox "found att"
Call item.Appendtext("<< Attachment removed : " + o.Source + " >>")
Call item.AddNewLine(1)
Call o.Remove
Msgbox "removed att"
Call doc.Save(1,0,1)
Msgbox "save"
End If
End Forall
Call Source.Close
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.EditDocument(Tru
Call session.SetEnvironmentVar(
Exit Sub
End Sub
ASKER
All that should be in an action or post open?
Hm. If I read the code correctly, the Draft will be removed when the next document is opened. It checks if there's a left-over, if yes it's removed. Is that correct?
I've got to read the code once again, very carefully, but I have very little time. Maybe later... Sorry for now.
I've got to read the code once again, very carefully, but I have very little time. Maybe later... Sorry for now.
We have a variation of this code in our mail template. I consider it horrid.
I believe our version deletes the draft off teh back end as soon as it is open in the UI, so there is no document saved if the reply is abandoned.
I believe our version deletes the draft off teh back end as soon as it is open in the UI, so there is no document saved if the reply is abandoned.
In the original code, isn't there supposed to be an agent that checks periodically if the DeleteAttachment environment variable exists? And deletes the Draft if it exists?
ASKER
I didn't realise it was doing that before it removes the attatchment. Thanks
Yeah I agree, it is kind of messy. Users on dialup would swear, loading the document with the attachements, then updating the removal of teh attachments, doubles the server access. But this is temporary until R6
In R6 there's a neat @command, [Composewithreference].
You mean that after you remove the attachments, you can delete document while it's open from within itself? can a uidoc exist without a doc?
I haven't see any agents in the article I found this in.
Yeah I agree, it is kind of messy. Users on dialup would swear, loading the document with the attachements, then updating the removal of teh attachments, doubles the server access. But this is temporary until R6
In R6 there's a neat @command, [Composewithreference].
You mean that after you remove the attachments, you can delete document while it's open from within itself? can a uidoc exist without a doc?
I haven't see any agents in the article I found this in.
BTW, it would be appropriate to cite your source.
ASKER
I had lost the URL.. I looked it up again, and it turns out to be someone on EE; madheeswar
heh heh, Madheeswar didn't write it either.
Funny, I haven;t heard from him in a while. He must have left the Singapopre job.
Funny, I haven;t heard from him in a while. He must have left the Singapopre job.
ASKER
"I believe our version deletes the draft off teh back end as soon as it is open in the UI, so there is no document saved if the reply is abandoned."
What do you mean?
What do you mean?
Thanks Sjef for pointing.
Qwaletee,
Don't have enought time to spend on EE> Yes, I have left Singapore and working in India for personal reasons.
miklesw,
Check this link:
http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/3d5e8c0e30dbc17185256d2b002f2641?OpenDocument
Qwaletee,
Don't have enought time to spend on EE> Yes, I have left Singapore and working in India for personal reasons.
miklesw,
Check this link:
http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/3d5e8c0e30dbc17185256d2b002f2641?OpenDocument
ASKER
I found another way of removing attachments.. This code goes in the action.. Seems to do the trick without having drafts.. the only prob is that the original document needs to be closed after removign teh attachments... the att will be removed(icon stays there)..until u re-open the doc...
source > http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/a8aa0fa7afb1b0898525691800612fe2?OpenDocument
I added a condition to check if it was opened in a view, so it could decide whether to close the original doc or not... Still that only applies when keeping the attachments..
Sub Click(Source As Button)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim tempdoc As NotesDocument
Set db = session.currentDatabase
Dim closeui As Boolean
Dim uidoc As NotesUIDocument
Set uidoc = ws.currentdocument
If uidoc Is Nothing Then
Call ws.EditDocument(False)
Set uidoc=ws.currentDocument
closeui = True
End If
Set doc = uidoc.document
' Check if the document has attachments , if not then do a normal reply with history
If doc.HasEmbedded = False Then
Call session.SetEnvironmentVar( "MailStEd", "9" )
Call ws.ComposeDocument("",""," Reply With History")
If closeui = True Then
Call uidoc.close
End If
Exit Sub
End If
' Check if the embedded object has atleast one attachment, if no then do a normal reply with history
Dim count As Integer
Dim item As NotesRichTextItem
Set item=doc.getFirstItem("bod y") ' get body
count = 0
Forall x In item.embeddedObjects
If x.type=1454 Then
count = 1
End If
End Forall
If count = 0 Then
Call session.SetEnvironmentVar( "MailStEd", "9" )
Call ws.ComposeDocument("",""," Reply With History")
If closeui = True Then
Call uidoc.close
End If
Exit Sub
End If
'prompt user if the mail has attachments to keep or remove
response= Msgbox("Do you wish to keep the attachments ?",32+4+256,"This message has file attachments...")
If response="6" Then
Call session.SetEnvironmentVar( "MailStEd", "9" )
Call ws.ComposeDocument("",""," Reply With History")
If closeui = True Then
Call uidoc.close
End If
Exit Sub
End If
Set tempdoc = New NotesDocument(db)
Set item=doc.getFirstItem("bod y") ' get rid of attachments from backgroud document
' Set up RichTextStyle
Dim richStyle As NotesRichTextStyle
Set richStyle = session.CreateRichTextStyl e
richStyle.NotesFont = FONT_COURIER
richStyle.FontSize = 10
Call item.AppendStyle(richStyle )
Call item.AddNewLine(2)
Call item.AddNewLine(1)
Forall x In item.embeddedObjects
If x.type=1454 Then
AttachmentName$ = x.source
Call item.Appendtext("<< Attachment Removed : " + AttachmentName$ + " >>")
Call item.AddNewLine(1)
x.remove
End If
End Forall
If closeui = True Then
Call uidoc.close
Else
uidoc.Close
'to reload to the document somehow
End If
Call doc.CopyAllItems(tempdoc,T rue)
Call tempdoc.MakeResponse( doc)
Call tempdoc.Save(True,False)
' open the tempdoc using the new memo form to create a rwh
Set uidoc = ws.EditDocument(True,tempd oc)
Call session.SetEnvironmentVar( "MailStEd", "9" )
Set anotheruidoc = ws.ComposeDocument("",""," Reply With History")
Print "Removed Attachment(s) from Reply To All with History..."
Dim refitemintempdoc As NotesItem
Set refitemintempdoc = tempdoc.GetFirstItem("$REF ")
Dim refitem As NotesItem
Set refitem = refitemintempdoc.CopyItemT oDocument( anotheruidoc.document,"$RE F")
'If closeui = True Then
Call uidoc.close
'End If
Call tempdoc.Remove(True)
End Sub
source > http://www-10.lotus.com/ldd/46dom.nsf/55c38d716d632d9b8525689b005ba1c0/a8aa0fa7afb1b0898525691800612fe2?OpenDocument
I added a condition to check if it was opened in a view, so it could decide whether to close the original doc or not... Still that only applies when keeping the attachments..
Sub Click(Source As Button)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim tempdoc As NotesDocument
Set db = session.currentDatabase
Dim closeui As Boolean
Dim uidoc As NotesUIDocument
Set uidoc = ws.currentdocument
If uidoc Is Nothing Then
Call ws.EditDocument(False)
Set uidoc=ws.currentDocument
closeui = True
End If
Set doc = uidoc.document
' Check if the document has attachments , if not then do a normal reply with history
If doc.HasEmbedded = False Then
Call session.SetEnvironmentVar(
Call ws.ComposeDocument("","","
If closeui = True Then
Call uidoc.close
End If
Exit Sub
End If
' Check if the embedded object has atleast one attachment, if no then do a normal reply with history
Dim count As Integer
Dim item As NotesRichTextItem
Set item=doc.getFirstItem("bod
count = 0
Forall x In item.embeddedObjects
If x.type=1454 Then
count = 1
End If
End Forall
If count = 0 Then
Call session.SetEnvironmentVar(
Call ws.ComposeDocument("","","
If closeui = True Then
Call uidoc.close
End If
Exit Sub
End If
'prompt user if the mail has attachments to keep or remove
response= Msgbox("Do you wish to keep the attachments ?",32+4+256,"This message has file attachments...")
If response="6" Then
Call session.SetEnvironmentVar(
Call ws.ComposeDocument("","","
If closeui = True Then
Call uidoc.close
End If
Exit Sub
End If
Set tempdoc = New NotesDocument(db)
Set item=doc.getFirstItem("bod
' Set up RichTextStyle
Dim richStyle As NotesRichTextStyle
Set richStyle = session.CreateRichTextStyl
richStyle.NotesFont = FONT_COURIER
richStyle.FontSize = 10
Call item.AppendStyle(richStyle
Call item.AddNewLine(2)
Call item.AddNewLine(1)
Forall x In item.embeddedObjects
If x.type=1454 Then
AttachmentName$ = x.source
Call item.Appendtext("<< Attachment Removed : " + AttachmentName$ + " >>")
Call item.AddNewLine(1)
x.remove
End If
End Forall
If closeui = True Then
Call uidoc.close
Else
uidoc.Close
'to reload to the document somehow
End If
Call doc.CopyAllItems(tempdoc,T
Call tempdoc.MakeResponse( doc)
Call tempdoc.Save(True,False)
' open the tempdoc using the new memo form to create a rwh
Set uidoc = ws.EditDocument(True,tempd
Call session.SetEnvironmentVar(
Set anotheruidoc = ws.ComposeDocument("","","
Print "Removed Attachment(s) from Reply To All with History..."
Dim refitemintempdoc As NotesItem
Set refitemintempdoc = tempdoc.GetFirstItem("$REF
Dim refitem As NotesItem
Set refitem = refitemintempdoc.CopyItemT
'If closeui = True Then
Call uidoc.close
'End If
Call tempdoc.Remove(True)
End Sub
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Suggested solution: handle the attachment(s), save the document, close it, reopen it using the UniversalID, make a copy in a new NotesDocument, delete the old (saved) document and open the new one to the user with EditDocument.