Rich text fields and cleaning

Hi everyone,

I am currently working on rich text fields and I was wondering :

I found no methods to clean a rich text field from its content. My question would then be :

How can I reset a rich text field ? May I delete the item on the NotesDocument and recreate it with the same name ? Would that be equal ? Or would it need to close and open the document again, …

Any suggestions might be helpful.

Kind regards,

Subject: Rich text fields and cleaning

Mathieu,

You are correct in your assertion that removing the item and creating another one with the same name will clear it out.

If you also want to refresh it in the front end you will have to resort to the back-end document close/open trick that has been discussed many times alerady in this forum. Search on “richtext and refresh”

If you are doing lots of rich text stuff you may want to consider looking at Ben L.'s Midas Rich Text product to help you out. It does cost a bit but it is a distinct improvement over the rich text functionality offered by Notes.

Subject: RE: Rich text fields and cleaning

Hi Dave,

Thank you for the answer. I have been thinking and I tried out some operations, but couldn’t manage to perform better than the deletion of the rich text field then the recreation.

Actually, I’m not considering buying an outside product since I have to do it on my own, but I will check this out by curiosity and who knows …

I’m sorry there is nothing obvious to do for cleaning a rich text field, these ones are a little bit tricky I find. That must be the price of strong possibilities.

Anyway, I used the refresh tips coming from a post in this forum, and that works perfectly wit my application, since I don’t use postopen and other events triggered when the UIDoc is opened.

I will stick to the deletion and manage with that. Thanks a lot for the answer, if anyone would like to add anything, be pleased.

Kind regards,

Subject: Rich text fields and cleaning

Mathieu,

If the rich text field contains file attachments, then the approach I use is to cycle through all the $FILE fields and delete them, then I delete the rich text field. Afterwards, I recreate the field as “New NotesRichTextItem(…)”.

If the rich text field merely contains text, I think you can get away with simply…

Call doc.ReplaceItemValue(“yourRichTextFieldName”, “”)

Ken A Collins

New York City

Subject: RE: Rich text fields and cleaning

hm, this sounds a bit alarmist. Normally when you use LS to remove an RT item that contains an attachment, Notes removes also the attachment (referenced by $FILE). In any case it would be troublesome if you have 2 or more RT items that each could contain attachments, right?

You might need this approach if you remove RT item by using C API, and then it’s up to you to figure out where the particular attachment has been referenced.

The second approach of replacing RT item with an empty string effectively replaces RT item with a text item. So if you use it afterwards to open the doc in UI it is equivalent to removing the item; if you use a code to manipulate it, you’ll have to check the item type before proceeding (you cannot expect RT), but being a bit defensive could be a good approach anyway.

Subject: RE: Rich text fields and cleaning

Hi Normunds,

You are absolutely right about the attachments and the RT. That could be really troublesome in case you may want to include an attachment in more than a RT. However, what could happen if you import the same file twice but in two different RT ? Would Lotus create two different files ? Under such circumstances, it wouldn’t be a problem to delete a RT. The only one problem would be in the case you copy/paste a RT attachment to another RT field, right ?

Using C would solve all this, because of the way C basically works. As for me, I’m strictly working in a Lotus environment, so I’m working woth LS, formulas and Java.

The problem of replacing RT item by a string is : if I append some texts, and attachments, … on the same RT, is it possible to replace it by a single string ? I didn’t notice any methods to do so. Well, since I didn’t doesn’t mean it doesn’t exist. Or I may be wrong when it comes to see, my eyes aren’t the best :wink:

Back to the subject, it could be a good way to be able to replace by a single string, I’m looking forward to discovering a means to !

Kind regards,

Subject: RE: Rich text fields and cleaning

Hi Ken,

I tried out your solution with : Call doc.ReplaceItemValue(“yourRichTextFieldName”, “”)

Actually my code looks like :

Dim ws As New NotesUIWorkspace

Dim uiDoc As NotesUIDocument

Dim doc As NotesDocument



Set uiDoc = ws.CurrentDocument

Set doc = uiDoc.Document

Call uiDoc.Document.ReplaceItemValue("MyItem", "")

Call doc.Save(False, False)

doc.SaveOptions = "0"

Call uiDoc.close

Set uiDoc = ws.EditDocument(True, doc, False)

Set doc = uiDoc.document

And it is working perfectly. I will stick to that, until I can’t use it anymore, because of queryopen/postopen events I might be bound to use.

Thanks for your help !

Kind regards,

Subject: RE: Rich text fields and cleaning

I’m not sure about your use case yet, but as your sample code contains UI objects, I’ll step in with an UI only suggestion.

The most simple and effective way to clear a RT item when a document is open for editing requires only one line of code: Simply use JavaScript to set the fields value property to “”.

Of course, this makes sense only, if you need the code in a button or action (or JS event).