Hi,Just thought I’d point out something about removing attachments.
My script is set up to create a duplicate document, some fields are set to Blank, we get a new unique reference, and a new date, and I wanted to remove the attachment…
According to the notes help, this is acheived by
- This script removes all file attachments from a document.
Dim doc As NotesDocument
'…set value of doc…
Call doc.RemoveItem( “$FILE” )
Call doc.Save( True, True )
My experience today has been that using the above remove, does remove the attachment, but leaves a nasty ‘shell’ attachment lieing around which gives 'Note Item Not found when clicked on.
So, instead, a better line is
'This line removes any and all File Attachments
Call duplicateDoc.RemoveItem( "$FILE" )
Call duplicateDoc.ReplaceItemValue("QuoteAsAttachment","")
Where QuoteAsAttachment is my Rich Text Field containing an attachment…
This may be of interest to those trying to delete attachments, or if you get Note Item Not Found…
Also, I’d just like to say THANKS to everyone out there who helped me create my LotusScript.
For prosperity’s sake, here is the script:-
Sub Click(Source As Button)
'Declares Workspace, Session, Database, and two NotesDocuments
Dim uiws As New NotesUIWorkspace
Dim session As New NotesSession
Dim currentDB As NotesDatabase
Dim currentDoc As NotesDocument
Dim duplicateDoc As NotesDocument
'Set the current database as the one currently being used
'And Set the current document to the one currently being edited
Set currentDB = session.CurrentDatabase
Set currentDoc = uiws.CurrentDocument.Document
'N.B - Though this is a Set Statement, it's the below line that's creating the document
Set duplicateDoc = New NotesDocument(currentDB)
'Then, copy ALL the items (fields etc) to the new document.
Call currentDoc.CopyAllItems(duplicateDoc)
'These two lines are just to create a new unique reference number
Dim eval As Variant
unique = Evaluate("@Unique", doc)
'Set values, e.g. new unique number, todays date, status back to Draft
'Product, Description, PaperSize, Sheets, Colours, Quantity, PPU and Line Tot
'All Blanked Out
Call duplicateDoc.ReplaceItemValue("OurRef", unique)
Call duplicateDoc.ReplaceItemValue("Date",Today)
Call duplicateDoc.ReplaceItemValue("Status","Draft")
Call duplicateDoc.ReplaceItemValue("Product","")
Call duplicateDoc.ReplaceItemValue("Description","")
Call duplicateDoc.ReplaceItemValue("PaperSize","")
Call duplicateDoc.ReplaceItemValue("Sheets","")
Call duplicateDoc.ReplaceItemValue("Colours","")
Call duplicateDoc.ReplaceItemValue("Quantity","")
Call duplicateDoc.ReplaceItemValue("PPU","")
Call duplicateDoc.ReplaceItemValue("LineTot","")
Call duplicateDoc.ReplaceItemValue("Hide","No")
Call duplicateDoc.ReplaceItemValue("Remove","No")
Call duplicateDoc.ReplaceItemValue("Count","0")
'Putting in these commented out lines in case Promotional Markets
'Want to reset the currency and per to blank when copying a Quote
'Call duplicateDoc.ReplaceItemValue("Currency","")
'Call duplicateDoc.ReplaceItemValue("Per","")
'Heres the clever bit. Using a For Loop, to avoid hundreds of lines of code
'An enhancement here would be to only perform this if the line contained values
For x = 1 To 9
Call duplicateDoc.ReplaceItemValue("Product"&x,"")
Call duplicateDoc.ReplaceItemValue("Description"&x,"")
Call duplicateDoc.ReplaceItemValue("PaperSize"&x,"")
Call duplicateDoc.ReplaceItemValue("Sheets"&x,"")
Call duplicateDoc.ReplaceItemValue("Colours"&x,"")
Call duplicateDoc.ReplaceItemValue("Quantity"&x,"")
Call duplicateDoc.ReplaceItemValue("PPU"&x,"")
Call duplicateDoc.ReplaceItemValue("LineTot_"&x,"")
Call duplicateDoc.ReplaceItemValue("Hide"&x,"No")
Call duplicateDoc.ReplaceItemValue("Remove"&x,"No")
Next
'Unfortunately, there was also a Remove10 field
'This simple If statement sets it to "No"
If x = 10 Then
Call duplicateDoc.ReplaceItemValue("Remove"&x,"No")
End If
'This line removes any and all File Attachments
Call duplicateDoc.RemoveItem( "$FILE" )
Call duplicateDoc.ReplaceItemValue("QuoteAsAttachment","")
'Definately Save the New Document
Call duplicateDoc.Save(True, True)
'Get a handle on the existing document in the frontend
'Then Close this document
Dim uidoc1 As notesuidocument
Set uidoc1 = uiws.currentdocument
uidoc1.Close
'Get a handle on the new document in the frontend
'Then Edit this document
Dim uidoc As NotesUIDocument
Set uiDoc = uiws.EditDocument(True, duplicateDoc)
End Sub