Attachments at bottom of form

Basic setup:Notes client

New doc or existing doc

RT Field - ‘AttachFiles’

I want to attach a specific file into the field ‘AttachFiles’ via LotusScript.

Everything I try dumps the file to the bottom of the form in the V2 attachment format.

I’ve searched this forum and the 4/5 forum without much luck. I’m sure something somebody has posted is the tip-off, but I’m just not seeing it.

What I’ve tried:

Dim rtitem as NotesItem

Dim object as NotesEmbeddedObject

Dim doc as NotesDocument

Set rtitem = doc.GetFirstItem(“AttachFiles”)

Set object = rtitem.EmbedObject(EMBED_OBJECT, “”,“c:\junk.txt”)

Call doc.save(true,false)

Set rtitem = doc.GetFirstItem(“AttachFiles”)

If (rtitem is nothing) then

Set rtitem = New NotesRichTextItem(doc,“AttachFile”);

Set object = rtitem.EmbedObject(EMBED_OBJECT, “”,“c:\junk.txt”)

End If

Call doc.save(true,false)

Set rtitem = New NotesRichTextItem(doc,“AttachFile”);

Set object = rtitem.EmbedObject(EMBED_OBJECT, “”,“c:\junk.txt”)

Call doc.save(true,false)

I’ve also tried it without using the doc.Save and letting the user save the doc via the UI - still at the bottom.

I have also considered saving the doc before attaching it in the hopes that the attachment field will be ‘add’ the field and magic would happen, but the app is part of a cluster and I’ve had some problems with rep/save docs popping up if you use code to do saves in rapid succession and I don’t want to go there if I don’t need to. If I re-run the current code on an existing doc, the attachments all wind up at the bottom anyway so I’m not sure doing a ‘pre-save-save’ would help anyway.

I guess in the greater scheme of things, having the attachment(s) at the bottom of the form isn’t a huge deal, but it’s gonna confuse folks and I’d prefer to have it in the intended field. (I mean look like it’s in the intended field, that $file with the link in the field thing is understood).

Thanks for any pointers.

Doug

Subject: I have something like this in an agent which is indeed putting the attachment inline

and this is running on the server, so I’m not sure why you see something different

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set doc = db.CreateDocument

Dim richStyle As NotesRichTextStyle

Dim richText As New NotesRichTextItem(doc, “Body”)

Set richStyle = session.CreateRichTextStyle

richStyle.Bold = True

Call richText.AppendStyle(richStyle)

'Append the original file into the document before it is deleted

Set object = richText.EmbedObject ( EMBED_ATTACHMENT, “”, ImageFileName)

SUBDeleteFile(ImageFileName)

ImageFileName = “”

Call richText.AppendText(text$) ’ Appends value to Content

'add a carriage return

Call richText.AddNewLine( 1 )

Subject: RE: I have something like this in an agent which is indeed putting the attachment inline

Interesting. One of the early replies in my thread: http://www-10.lotus.com/ldd/nd6forum.nsf/ShowMyTopicsAllFlatweb/f5a0c912383d9032852573b400749a3e?OpenDocument talks about front end/back end issues. If you’re doing this via a scheduled server agent, you’re dealing only with the back end. I need to have the doc open for the user who’s dealing with stuff in the front end, and then my code mucks in the back end.

I’m going to try the V2AttachmentOptions thing and see if it matters at all.

Thanks for the reply.

Doug

Subject: Ah my ciode is running as a scheduled agent.

This may sound crazy, but can you use @command functions?

Subject: RE: Ah my ciode is running as a scheduled agent.

I don’t think so but maybe I can.

What’s actually going on is:

User presses a button.

@Command launches a file specified in a field on the text which starts a subassembly tester.

Simultaneously with the tester start, a LS routine starts up.

It creates a lock file indicating the tester is running.

My code goes into a loop: file there? Yes. look again, repeat.

When the tester is done, it creates a text file containing test data and stores it on a network share.

It also kills the lock file so my code knows the tester is done.

I find the data directory and file and parse it into an MS SQL db.

The file is attached to the Notes document.

The data file is moved to a ‘done’ directory, delete the data dir, and I’m done.

I guess I could convert the subroutine into an agent call and make the agent use @functions…might work but I’ll need to be careful that everything works in the right order and shelling out of a sub in an agent to another agent doesn’t make the server throw up…

Time for a break.

Thanks for the help.

Doug

Subject: Attachments at bottom of form

You say that the field on the form is named AttachFiles, but the field you create through LS is named AttachFile, and that is the problem.

The field to which the file is attached doesn’t exist on the form, so the file goes at the bottom.

/Peter

Subject: Typo in post, not the code.

Not two field names, just a stupid typo on the post.

Field name: ‘AttachFiles’

Code uses: ‘AttachFiles’

If only 'twere that simple.

Doug

Subject: RE: Attachments at bottom of form

Finally one guy not sitting on his eyes! I’ve been staring at the code and couldn’t find what was wrong. Always amazing how your brain can fool you.

Subject: RE: Attachments at bottom of form

Actually, there’s one more problem here, that I didn’t spot before. The line

Set object = rtitem.EmbedObject(EMBED_OBJECT, “”,“c:\junk.txt”)

should actually be

Set object = rtitem.EmbedObject(EMBED_ATTACHMENT, “”,“c:\junk.txt”)

/Peter

Subject: Attachments at bottom of form

Hello Doug,

This is interesting, I seem to recall doing this several times in various projetcs and I enver encountered this problem.

However, I am wondering: are you are attaching the file from the front end or the backend ?

Because RTF fields aren’t working very well once it is opened in the front end. To do this, you would need to have the document NOT in the UI, and work all the attachment process in the backend; then once you open it, it would be correct.

Maybe Ben can tell us more on this, as his knowledge of RTF is greater?

There is also a v2attachmentOption field you can add to force attachments in v2 style or not, but I think by default it should be correctly attached to a field.

Let me know how it goes, I am curious to know.

Subject: RE: Attachments at bottom of form

The attach code uses doc so it’s working on the back end. The document is, however, open in the front end since there is stuff the user needs to do

I’ll give the V2AttachmentOption a go and see what happens - all other posts I’ve seen say this is for web only and my app is 100% client.

I’ll let you know what happens.

Doug

Subject: Attachments at bottom of form

Ugly, but… unless Ben (or someone) comes up with some magic incantation, you’re going need to save the uidoc, attach the file in the back-end, save the back end doc, close the uidoc, then reopen the uidoc.

Subject: RE: Attachments at bottom of form

Rich,

Sounds like you and Carl are on the same page for this one and it ain’t gonna happen. This is a fairly old app (released in '97 as a 3.2 app) with LOTS of growth by accretion and I’m really afraid if I start mucking about in the QS code the thing will implode.

We’re just going to have to get used to seeing attachments at the bottom of the form…

Happy holidays to you and yours.

Doug

Subject: Final resolution

Objective:Provide the user with a method to automatically find a file, do some processing (parse some data into a relational db), and attach the file to a Notes document into a front end RT field for the attachment.

Things tried:

Regular LS drops the file into a V2Attachment field at the bottom of the form. It works, but can be confusing.

The Jan/Feb '08 issue of The VIEW has a nice little trick that works great - split the process into two pieces: Use a LS to find the file and pass the name to an environmental variable, then call an @Function agent to go to the attachment field, and insert the file based on the INI variable! Short and sweet, works like a charm if the code resides in or is called by the form containing th RT field.

Problem:

My design is a ‘plug in’ for another app and uses an @Dialog box to do the ‘find, process, attach’ functions. @Dialog can’t pass RT items back to the source document. I can’t move the code into the source document (impacts the design of the underlying system and isn’t an option).

Resolution:

Use @Dialog to launch the find/process/attach code.

Use LS code to do everything.

The attachment shows up as a V2Attachment.

Ohhhh so close…

Subject: RE: Final resolution

I know this thread was a long time ago, but for anyone still wrestling with this, the only way I have found to deal with getting attachments via a dialog is to get the file path and filename as text, then use LS to attach it from the file system - you probably got this already…

Subject: Attachments at bottom of form

Attachments show at the bottom of the form …this is default behavior. You should have a $V2AttachmentOptions field as computed and set its value as “0” so that attachments wont show at the bottom.

Take a look at the below link for custom attachments implementation:

http://www.codestore.net/store.nsf/unid/DOMM-4T4ME3?OpenDocument

Thanks

Viswa.

Subject: I thought V2AttachmentOptions was web

All of the posts I’ve seen that discuss this field say it’s for web apps only which is why I didn’t try coding it.

I’ll add the field and see what happens.

Off to follow your link…

Thanks.

Doug

Subject: RE: Attachments at bottom of form

Hi,

I am facing the similar problem in Lotus Notes Client 7.5.

I have Rich Text field where I allow users to attach files from the frontend. Users attach the files using File–>Attach and click Submit button (the button does normal saving of document and sending mails). However, when I reopen the document after doing this, I find the attachment goes to the bottom of the document.

How do I resolve the issue in a Client based application ?

Any suggestions ?

Thanks & Regards,

Megha.

Subject: $V2AttachmentOptions - no joy

$v2attachmentoptions does nothing.

Just fer grins…on the chance that there really IS a typo buried in the code…here it is in all it’s ugly glory:

Button on a form calls an agent.

Agent contains sub routines.

Here’s the attach sub:

Sub AttachXMLFile(UIWS As NotesUIWorkspace, FN As Variant)

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject



Set uidoc = UIWS.CurrentDocument

Set doc = uidoc.Document

Set rtitem = New NotesRichTextItem( doc, "AttachFiles" )

Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", FN)

End Sub

Thank you to everyone who posted, it’s very much appreciated.

Doug

Subject: RE: $V2AttachmentOptions - no joy

Well, what I see from this code, is that you are creating a new RTF field.

If you are creating this in the backend, yet the document is already opened in the front end, then forget it - it will not behave as expected, because Rich Text Fields won’t update correctly while the front end is opened.

You would need to process this in the backend completely first, including a call to update() and then save, then once this is done, you could open it on the front end. Assuming that there is a matching RT field on the UI form, normally, it should attach it and display it correctly…

Keep me posted, i’d be curious to know how this gets solved!