createDocument not working properly in Java Agent

I’m having some problems creating a document with an agent, and I think that it might just be something small I’m overlooking.

I’ve got

 Database db = agentContext.getCurrentDatabase();

 Document doc = db.createDocument();

 doc.appendItemValue("Form", "MainTopic");

 doc.appendItemValue("Subject","CreateRichTextItem");

 // Create rich text item and append text

 RichTextItem rti = doc.createRichTextItem("Body");

 rti.appendText("First paragraph.");

 rti.addNewLine(1);

 rti.appendText("Second paragraph.");

 doc.save(true, true);

from the help file, so it should be right. The document shows up in the view, but it isn’t being created correctly. At first, it was giving me an error: “Cannot locate form : MainTopic”, then “Cannot locate Default Form”. So I created a blank form named MainTopic and saved it. I no longer get the error messages when I open the newly created documents, but they are blank.

Does anyone know what I’m doing wrong?

Subject: createDocument not working properly in Java Agent

Do you have a Subject and Body field on your MainTopic form?

Your code is just creating a document, not a form. To view the document in the ui you need a form that has the corresponding fields.

Subject: RE: createDocument not working properly in Java Agent

That was the problem. Thank you so much!