Few days back I was analyzing one requirement in Quickplace where my user wish to get all the attachments from his entire Quickplace.When I saw the Quickplace ,I found its having more than 20 notes(.nsf) instances and size was more than 5GB. Initially I have thought it would be simple agent which will read all the instances in specific folder and will extract on the server's specific drive.By keeping this in mind I have wrote the agent in jiffy.

Code was something like ,

strParentRoom="ParentRoom"
Mkdir "D:\QP Backup\XXXXX\"& strname
tmppath="D:\QP Backup\XXXXX\"& strname & "\"
While Not vwEntry Is Nothing

Set doc=vwEntry.Document
If doc.HasItem("PageBody") Then
Set rtitem = doc.GetFirstItem( "PageBody" )
If doc.Hasitem("$file") Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
fileCount = fileCount + 1
Call object.ExtractFile(tmppath & Cstr(filename)))
End If
End Forall
End If
End If

Set vwEntry=vwEntryColl.GetNextEntry(vwEntry)
Wend

I had started running the code with smiley face and got surprise when it had thrown the error saying "Type mismatch".I had checked in debugger and found few documents having attachment in the document but not in RT field.So, following line started giving problem,

Forall o In rtitem.EmbeddedObjects

(Since, rtitem was empty)

I had opened the lotus help file and started digging around and found if attachment is not in RT field , go for "EmbeddedObjects" method in NotesDocument class.I had modified my code and tested again , Again it was same error at same line .

After spending good time in small issue, I found solid idea to work with this issue.
So, My new code was something like ,

Set vwEntry=vwEntryColl.GetFirstEntry

strname="ParentRoom"
Mkdir "D:\QP Backup\XXXXX\"& strname
tmppath="D:\QP Backup\XXXXX\"& strname & "\"
While Not vwEntry Is Nothing

Set doc=vwEntry.Document
If doc.HasItem("PageBody") Then
Set rtitem = doc.GetFirstItem( "PageBody" )
If doc.Hasitem("$file") Then
If ( rtitem.Type = RICHTEXT ) Then
macro=Evaluate({@attachmentnames},doc)
For icount=0 To Ubound(macro)
Set object = doc.GetAttachment( macro(icount) )
fileCount = fileCount + 1
Call object.ExtractFile(tmppath & Cstr(macro(icount)))
Next
End If
End If
End If

Set vwEntry=vwEntryColl.GetNextEntry(vwEntry)
Wend

pretty simple , huh :)

I had tested with all the possible ways and found it will work with both scenarios (field and document level attachment).

I would like to see if someone comes with some new logic .

preload preload preload