Copying an attachment into a computed field

I have one editable RT field (fFollowUpTextToAdd) and one computed RT field (fFollowUp). I want to add data in 1’st field, hit the button and add those data in 2’nd RT field (computed, so users can not change the content). Everything works gread, only attachments not. If I click the attachment icon in computed RT field, I receive ‘Note Item not found error’.

I suppose, this has something to do with the RT refresh (it seems, that attachment has not been saved), but if I call uidoc.save, or doc.save just after I compose the final RT field, nothing is changed and I still receive the same error.

Something similar can be found here: http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/079017449918b7528525719900576d8e?OpenDocument, but I don’t see any helpful answer in this post.

Here is the code without any changes !!!

Sub Click(Source As Button)

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim uidocNew As NotesUIDocument

Dim doc As NotesDocument

Dim username As NotesName

Dim richStyleNormal As NotesRichTextStyle

Dim richStyleBold As NotesRichTextStyle

Dim rtnav As NotesRichTextNavigator

Dim rtitemHistory As notesrichtextitem

Dim rtitemToInsert As notesrichtextitem

Dim rtitemTemp1 As NotesRichTextItem

Dim rtitemTemp2 As NotesRichTextItem

Dim hdr As String

Dim recipients As Variant

Dim cc As Variant

Dim subj As String

REM some declarations are global



Const FLD_RECIPIENTS = "fTaskLeader"

Const FLD_CC = "cpyTo"

Const FLD_RTITEM_TEMP1= "tempRTItem1"

Const FLD_RTITEM_TEMP2 = "tempRTItem2"

Const FLD_HISTORY = "fFollowUp" 'history field

Const FLD_TEXT_TO_ADD = "fFollowUpTextToAdd" 'text you want to add in history field



REM Compose title

Set userName = session.CreateName(session.UserName)

hdr = "("+Cstr(Date)+", "+Cstr(Time)+", "+userName.Common+")"



REM define the rich text font styles	



REM first bold style

Set richStyleBold = session.CreateRichTextStyle

richStyleBold.NotesFont = FONT_COURIER

richStyleBold.FontSize = 10

richStyleBold.Bold = True

richStyleBold.NotesColor = COLOR_DARK_BLUE



REM second the normal style

Set richStyleNormal = session.CreateRichTextStyle

richStyleNormal.NotesFont = FONT_COURIER

richStyleNormal.FontSize = 10

richStyleNormal.Bold = False



Set uidoc = ws.CurrentDocument

REM refresh the RT fields ..   

Call uidoc.Refresh(True)

Set doc = uidoc.Document



REM create and get  all necessary rich text items 

Set rtitemHistory = doc.GetFirstItem(FLD_HISTORY)

Set rtitemToInsert = doc.GetFirstItem(FLD_TEXT_TO_ADD)

While Not doc.HasItem(FLD_RTITEM_TEMP1)

	Set rtitemTemp1 = doc.CreateRichTextItem(FLD_RTITEM_TEMP1)

Wend		

While Not doc.HasItem(FLD_RTITEM_TEMP2)

	Set rtitemTemp2 = doc.CreateRichTextItem(FLD_RTITEM_TEMP2)

Wend



REM prepare the header data you want to insert in the history field

Call rtitemTemp1.AppendStyle(richStyleBold)

Call rtitemTemp1.AppendText(hdr+": ")

Call rtitemTemp1.AppendStyle(richStyleNormal)

Call rtitemTemp1.AddNewLine(2)

Call rtitemTemp1.AppendRTItem(rtitemToInsert)

Call rtitemTemp1.AddNewLine(2)



REM remember the content of rtitemHistory first

Call rtitemTemp2.AppendRTItem(rtitemHistory)



REM We need to clear the history in the history field. To clear the field, first delete it and create from scratch

While doc.HasItem(FLD_HISTORY)

	Call doc.RemoveItem(FLD_HISTORY)

Wend



REM then create the history field from scratch

Set rtitemHistory = doc.CreateRichTextItem(FLD_HISTORY)



REM bring the RT field to front, so I can read it programatically

Call uidoc.Refresh(True)



REM first add to history the new data (they will be on the top of the history - WHICH IS A DEMAND) 

Call rtitemHistory.AppendRTItem(rtitemTemp1)



REM then add data, which have been in history field before

Call rtitemHistory.AppendRTItem(rtitemTemp2)





REM delete the temporary rich text fields. We don't need them any more

While doc.HasItem(FLD_RTITEM_TEMP1)

	Call doc.RemoveItem(FLD_RTITEM_TEMP1) ' Wipe out the temp field

Wend		

While doc.HasItem(FLD_RTITEM_TEMP2)

	Call doc.RemoveItem(FLD_RTITEM_TEMP2) ' Wipe out the temp field

Wend	



REM Call uidoc.Refresh(True)

Call rtitemHistory.Update	



REM close and reopen the document, so the RT changes are updated on the fly

doc.SaveOptions = "0"

Call uidoc.Close(True)

Set uidocNew = ws.EditDocument(True, doc, , , , True)

Call uidocNew.Reload()

Call uidocNew.FieldSetText(FLD_TEXT_TO_ADD,"")

Delete uidoc

uidocNew.Document.RemoveItem("SaveOptions")

End Sub

Subject: Copying an attachment into a computed field

One simple rule of rich text field is that, the rich text content having attachments are updated only when the document is saved.

Rich text fields are different unlike normal text fields. In case of text fields, information is just plain text so you can write the contents to another computed field without any problem.

As rich text fields contains rich text formatting like… bold, tables, sections, attachments, objects etc you cannot move the contents to another field just like that.

You need to save the document so that all the contents are saved and then you can move the same to computed field.

–Phani

Subject: RE: Copying an attachment into a computed field

Hi all,

I encounter this problem also as I have Field A which is a editable rich text and a Field B (Text, computed for display) which computes value A. But it is strange though. sometimes it appears, sometimes it doesn’t. Especially when Print Preview. The attachments image are gone. Hope that there are other workaround solution to make the Print Preview visible for those attachments.

Oh and also, i did not encounter this error ‘Note Item not found error’. But when i try to view the field in properties. i got NSD error.

Subject: RE: Copying an attachment into a computed field

Hi Mandy,

How do you update the RT field? Do you programatically close and reopen the document to update it, or you have to close and reopen manually.

If you are doing this programatically, can you please post your code here, so I can see your solution?

Thx

Juraj

Subject: RE: Copying an attachment into a computed field

Good day Juraj,

Thanks for the speedy reply =)

Field A (rich text, editable). Default value is A (Hide formula : Role is not equal to Purchasing dept)

Field B (Text, computed for display). Default value is A (Display to all departments so they can view)

Manually

When user enter a attachment on Field A, then they save and close.

Other dept User will open the document and will see Field B (which is the attachment of Field A)

I didn’t use any codes or script. Its a simple computations of Field A to Field B.

They can see the attachment when they open the document.

But when they print preview. The attachment will be gone.

And when i try to see the document properties of Field A and Field B. IT will gives me NSD error.


Hi Juraj,

I know why when print preview, Field B is not displaying.

As Field A is (hide when print) though Field B is (not Hide when print)

This happen to attachments only. Cos I have a lot of about fields in this form that computes value of A but are mostly text field.

But hope that you can have a workaround to display the attachments when print cos text seems perfectly ok. sigh…

Thanks again

Mandy

Subject: RE: Copying an attachment into a computed field

The NotesRichTextItemRange and NotesRichTextItemNavigator classes let you create an insertion point within the rich text (at the top, for instance) so that you do not need to copy an entire rich text to a temporary item just to insert something someplace other than at the end.

Calling the Update method may be useful. Do this after you’ve added something to a rich text item and need to make sure all the changes have been resolved, before you use the rich text for something else.

Subject: RE: Copying an attachment into a computed field

Hi Andre,

the NotesRichTextNavigator class was the first thing I have used, but there is a notes bug involved:

http://www-1.ibm.com/support/docview.wss?rs=0&q1=AppendRTItem&uid=swg21114718&loc=en_US&cs=utf-8&cc=us&lang=en

If you call AppendRTItem method after BeginInsert method, you receive “Method is not available” error.

That’s the reason I use my workarround.

Juraj

Subject: RE: Copying an attachment into a computed field

Ok. Calling Update may still help.