(Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Subject: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hello Madhu,

U had earlier raised the same topic and Ian Scott had responded . Please check ur earlier thread.

Here it is :

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/6aaa6fd8b5f31d8e85257230004f0c34?OpenDocument

HTH

Tom

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hi Tom,Actually, I tried the solution given by Ian Scott but it din’t work which, I think, was because of my lack of understanding of his solution.

I request you to kindly explain me the same or suggest an alternative for the same.

Thank you,

Madhunandan

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hi ,

First thing first, ru trying to attach a file into the RTF Field? Coz “document” can be anything , can be a mail document, word document anything , text file etc.

From the earlier thread here are few things which I can figure out :

  1. The person who wants to put the “document” should have Write access on the document , otherwise u cannot put the file as per ur requirement.

  2. U can use NotesRichtextItem , NotesEmbeddedObject classes and OpenFileDialog method in your script for firstly getting handle of the RTF field where you want to embed the object , OpenFileDialog for getting the handle for the file you want to embed and NotesEmbeddedObject class and its methods for putting the “document” in the document u want to.

Also, if u can post where u r facing the problem , it would be gr8 for more understanding.

cheers

Tom

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hi Tom,I am not bothered about the person who is going to attach a document or whatever.

I want to know how I can get the handle of the RTF field where I want to embed an attachment, WITHOUT opening the current document in EDIT mode.

After this, I will use the OpenFileDialog to allow the user to select the file or document or whatever to attach it to the RTF field selected earlier

Cheers,

Madhunandan

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Well,

U can use UnprocessedDocuments property of the NotesDatabase class to get the handle of the document and the to the RTF item where u want to put the file. The user selects the document in the view .

U can also use an agent that runs on Selected Documents in a view , which could also solve ur problem.

HTH

Tom

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hi Tom,Well, I’m afraid you are not getting the situation still. I will try to explain:

The user opens a document called Release document and in that goes to a tab called SIGNOFF section. There, before signing off, he can attach a document (in a RTF) to that particular section for which he is the responsible signoff person. But, while attaching, he should not open the current document in edit mode (which can be done by double clicking anywhere on the document). Without opening the document in edit mode, he should click the ATTCH button and be able to select a file and attach it.

I hope, I have given you more details with this.

Cheers,

Madhunandan

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

I’m not surprised we’re not getting the situation at all. This last post finally has a bit of detail in it at least.

Are you asking how to attach a file to a document (“Response”) while it is open in read mode while preventing the user from being able to switch the document into edit mode?

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hi Ian,That’s exactly what I want to do. Sorry for the confusion I created which was due to me being a novice in Lotus Notes.

I hope I would get the solution now! :slight_smile:

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

In the Querymodechange event of the form you need something like this to prevent the user switching the document into edit mode:

If Not ( Source.EditMode ) Then

continue = False

End If

In the Queryopen event of the form you need something like this to prevent the user opening the document in edit mode directly from the view:

If ( Source.EditMode ) Then

continue = False

End If

If the document is open you can get a handle on the back end doc as follows:

Dim ws as New NotesUIWorkspace

Dim uidoc as NotesUIDocument

Dim doc as NotesDocument

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document

To attach the file you need something like this:

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject

Set rtitem = New NotesRichTextItem ( doc , “Body” )

filename = ws.OpenFileDialog ( True , “Select file to attach” , , , )

If Not ( Isempty ( filename ) ) Then

Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT , “” , filename )

End If

That all said, I think the suggestion that thomas made with respect to performing the operation from a view action is best. If the user attaches the file at the back end it will not appear in the ui until after the document has been closed and reopened.

I’m wary of getting further involved with this; if you put the code I’ve suggested in the postopen and querymode change events you’ll probably need to apply other conditions to the ‘if’ statement otherwise the user will not be able to create the document in the ui or edit it prior to or after this stage in its life.

Sorry to be blunt but this no longer seems to me to be a question about attaching files to a document but is instead a question about how to control read/edit mode and the answer to that very much depends upon the stages the document goes through during its life. If it needs to be edited later or prior to this stage it could get complicated.

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

You might also consider making the rich text field a computed field and placing it on a subform which you conditionally load based on a flag you set when attaching the file. This way, unless there are other reasons for not permitting the user to switch the document into edit mode it may not matter two hoots if the document is in fact switched into edit mode since the rich text field will be computed and so cannot be edited.

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

Hi Ian/Tom,Can you tell me if this works:

I put that RTF (“Attachment”) in a subform & then below the RTF, I create a button - ATTACH DOCUMENT (in the subform itself) with this formula:

@Command([EditGotoField];“Attachment”);

@Command([EditInsertFileAttachment])

Will this open even the main form in EDIT mode? What I am assuming is that only the subform will be opened in EDIT mode and not the main form.

Cheers,

Madhunandan

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

The subform is part of the form. If you open a ‘main’ document in edit mode the subform component will also be in edit mode and if you open the ‘main’ document in read mode the subform will also be in read mode.

It sounds to me like you want the RTF to not be editable in which case you can make it a computed RTF (computes to itself).

Thomas suggested doing all this from a view action and he’s spot on. Try putting something like this in a view action button:

Dim sess As NotesSession

Dim ws as New NotesUIWorkspace

Dim doc as NotesDocument

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject

Dim answer as Integer

Set doc = sess.DocumentContext

Set rtitem = New NotesRichTextItem ( doc , “Attachment” )

filename = ws.OpenFileDialog ( False , “Select file to attach” , , , )

If Not ( Isempty ( filename ) ) Then

Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT , “” , filename )

doc.AttachmentFlag = “1”

Call doc.Save ( True , True )

Else

answer% = Messagebox ( “No file was selected. The process has terminated.” , 0+32 , “Attach File” )

End If

Then add a hidden editable text field to the form called “AttachmentFlag”.

Then create a subform (called ‘SubForm1’, say) and put a computed rich text field on it called “Attachment” and compute it’s value to its own name.

Then put the subform on the form and compute it with a formula such as:

@If(AttachmentFlag=“1”;“SubForm1”;“”)

Now, when you highlight the document in the view and click the action button the user will be able to select the file and the script will attach the file at the back end. When/if the user opens the document - even in edit mode - they will not be able to edit the file attachment because it is computed. Also, the subform will not load until a file has been attached.

You might also want to put a hide when formula on the view action button (AttachmentFlag=“1”) to prevent a user from attaching a second file - assuming you have ‘evaluate actions for every document change’ selected in the view properties. Alternatively you can check to see if the value is already set prior to displaying the file dialog and have the script present the user with a message if it is set.

If preventing the user from editing the document is still an issue try coding the QueryOpen and QueryModeChange events as I have previously suggested.

Experimenting on a local test database is good.

BTW. It sound like your question should have been “How do I prevent a user from editing an attachment on a document?” but maybe I’m wrong and there are other reasons why the document cannot be allowed to switch into edit mode.

Good Luck

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

should have been:

filename = ws.OpenFileDialog ( False, “Select file to attach” , , , )

for a single file to attach

Subject: RE: (Very Urgent)How to attach a document to a Rich Text field WITHOUT opening the current document in EDIT mode?

I agree with u Ian…Now only the requirement is clear…:-))