Reid Rivenburgh
Reid Rivenburgh

Reputation: 403

How to set the content of a RichTextItem field in a Notes document?

This one seems like it should be simple enough. I'm writing a Notes Agent in Java; it calculates a fairly large amount of numeric data (a 6400-entry array of doubles) that I want to store in an existing document, updating a field. Because of Notes' field limitations, I figured I needed to use a RichText field to do that. (My initial attempt to write to a multi-value Number field resulted in it failing to save somewhere between an array of size 4000 and 5000.) It's not clear to me how one stores that value in a RichTextItem, though. All my attempts have failed. In one case, using doc.replaceItemValue(), it seemed to convert the item to a Text List. Getting the item, casting it to a RichTextItem, and calling setValues() or setValueString() doesn't seem to do anything. This shouldn't be this hard! Any pointers?

(Alternately: Any better suggestion for how to store my array in a document in the database?)

Thanks, Reid

Upvotes: 1

Views: 2487

Answers (3)

Normunds Kalnberzins
Normunds Kalnberzins

Reputation: 1245

As for the question of "better" solution. I've recently written some code where I serialize/deserialize Java objects as JSON strings. This way they are well readable and easily restorable. I guess for the plain array it's a little problem. Especially if you do not want to restore it and have not interest to look at it (well, but probably it should be one or other :-)

And yes, you have to store it in the rich text anyway. Alternative you might write a text document and attach it in the RT field (again RT :-). Pretty usual scenario and easy to do.

Finally you could store data as database objects, but I guess from Java you do not really have access to do it. And it does not seem to be in any way better.

Upvotes: 1

nempoBu4
nempoBu4

Reputation: 6621

You can bypass the Notes' field limitations. You can flag your item as «contains non-summary data» by using the NotesItem.IsSummary property. You need to set this property to false. But remember, you cannot use this item in views and folders.
Here is example:

Vector vector = new Vector();

for (int index = 0; index<6400;index++)
    vector.addElement(new Double(Math.random()*100));

Item item = document.replaceItemValue("YourFieldName", vector);
item.setSummary(false);

document.save(true,true);

Upvotes: 1

Ken Pespisa
Ken Pespisa

Reputation: 22266

You'll need to create a RichTextItem and use the methods on that object to populate it:

import lotus.domino.*;
import java.util.Vector;
public class JavaAgent extends AgentBase {
 public void NotesMain() {
   try {
     Session session = getSession();
     AgentContext agentContext = 
     session.getAgentContext();
     // (Your code goes here) 
     Database db = agentContext.getCurrentDatabase();
     Document doc = db.createDocument();
     Item subject = doc.replaceItemValue("Subject", 
     "Project description");
     RichTextItem body = doc.createRichTextItem("Body");
     body.appendText("Cartoon book for children 
      ages 9-12");
     // Print text of subject and body
     System.out.println(subject.getText());
     System.out.println(body.getText());

   // Save the document
     doc.save(true, true);
   } catch(Exception e) {
     e.printStackTrace();
   }
 }
}

UPDATE:

If you need to edit an existing document, instead of creating a new rich text item, you would get the existing one.

RichTextItem body = doc.GetFirstItem("Body");  // instead of createRichTextItem

Upvotes: 3

Related Questions