Problems with Embedded Objects
(This may be the beginning of something that should spawn into a seperate blog. It’s also of no interest to anyone but myself and other Domino developers. In fact, I could be the only Domino developer on the planet who couldn’t suss this but just in case…)
I’ve been trying to extact file attachments from Notes documents using Lotusscript. In theory, this should be one of the most simplistic coding challenges I’ll face today and second only in brain processing power to blinking, or perhaps breathing.
The code should go something like this:
If doc.hasembedded Then
Forall o In doc.embeddedobjects
Set obj = doc.getattachment(o.name)
Call obj.extract(FILEPATH + o.name)
End Forall
End If
But the code failed when it got to the Forall command and through up a Type Mismatch error. Now normally this error would occur because there aren’t any attachments on the document. But this is something we checked for in the previous line. So what’s going on?
This particular application is accessed through the browser and only through the browser. That means that files are attached to the document can only be attached by use of a File Upload Control which in turn means that the files are attached directly to the document and not to a rich text field as they would if the document had been created through a Notes client.
Again in theory, this shouldn’t cause a problem: I should still be able to use the embeddedobjects array property of the NotesDocument object to get to the files. But I can’t. I know the files are kosher and not corrupted, I know they exist and I can access them through more conventional means. So how am I going to access them programatically now?
After a bit of headscratching and a cup of weak, machine-vomited coffee, the workaround presented itself and was just as simplistic as the original code. All I needed to be able to save the file to another location was the file name and another way of being able to get that name was with the formula function @AttachmentNames. So my new code looks like this:
Dim filenames as Variant
...
If doc.hasembedded Then
filenames = Evaluate("@AttachmentNames", doc)
Forall o In filenames
Set obj = doc.getattachment(o)
Call obj.extract(FILEPATH + o)
End Forall
End If
It’s a shame that the documented method doesn’t work and that you have to find a workaround, however simplistic it is. Still, if they’re going to work with 8 year old software that’s two versions behind the current release, what do they expect?
