ShowTable of Contents
The NotesUI API builds a bridge between XPages development and classic Notes development. It offers most of the functionality of the new
Notes UI API that Eclipse developers can use since Lotus Notes 8.5.1 (with updated content for 8.5.2) to access classic Notes design elements.
Available functionality
Here are a few use cases for using the Notes UI API:
- read/write field values on UI documents
- read selected entries from a Notes view
- open design elements (e.g. document/view/frameset)
- create a temporary document that can be used to store and pass data
- execute LotusScript code that accesses the Notes UI (not just a backend agent)
- and compose operations to create new documents with predefined fields
This article demonstrates how to compose new documents with predefined fields.
The base class of the XPages2Eclipse NotesUI API IRemoteNotesUITools
can be accessed by calling the getTools
method of the NotesUIAPI class:
var conn=X2E.createConnection();
var notesUITools=com.x2e.NotesUIAPI.getTools(conn);
The most relevant method of IRemoteNotesUITools
is getNotesUIWorkspace
which, similar to the LotusScript class with the same name, gives access to the user interface of the classic Lotus Notes Client:
var ws=notesUITools.getNotesUIWorkspace();
var uiview=ws.getCurrentView();
var uidoc=ws.getCurrentDocument();
var uiDocForPart=ws.getUIDocument(aWorkbenchPart); //tries to convert an Eclipse workbench part to an UI document or view
var uiViewForPart=ws.getUIView(aWorkbenchPart);
ws.openUrl("notes:///C1257899003DFAC4?OpenDatabase");
Sample application: Composing new documents
Our sample application contains a form to enter the field values for a new email:
When the button "Compose a memo with HTML" is clicked, all field values are read and transferred into a new temporary document:
//read field values:
var subject=getComponent("Subject").getValue();
var sendTo=getComponent("SendTo").getValue();
var cc=getComponent("CopyTo").getValue();
var bcc=getComponent("BlindCopyTo").getValue();
var htmlCode=getComponent("bodyHTML").getValue();
var filePath=getComponent("filePath").getValue();
//get access to NotesUI API
var conn=X2E.createConnection();
var notesUITools=com.x2e.NotesUIAPI.getTools(conn);
var ws=notesUITools.getNotesUIWorkspace();
session.setConvertMime(false);
//create temporary document as a template for the new email
var tempDbPath=notesUITools.getTempDbPath();
var tempDb=session.getDatabase("", tempDbPath);
var tmpDoc=tempDb.createDocument();
tmpDoc.replaceItemValue("Form", "Memo");
tmpDoc.replaceItemValue("Subject", subject);
tmpDoc.replaceItemValue("SendTo", toVector(@Explode(sendTo,",")));
tmpDoc.replaceItemValue("CopyTo", toVector(@Explode(cc,",")));
tmpDoc.replaceItemValue("BlindCopyTo", toVector(@Explode(bcc,",")));
//set the flag $DelayedImagesOK to let Notes load any embedded images in the richtext field
tmpDoc.replaceItemValue("$DelayedImagesOK", "ok");
...
The HTML code for the body field is imported as a MIME richtext field:
var bodyStream = session.createStream();
bodyStream.writeText(htmlCode);
var body = tmpDoc.createMIMEEntity("Body");
body.setContentFromText(bodyStream, "text/html;charset=iso-8859-1", 1726); //MIMEEntity.ENC_QUOTED_PRINTABLE
if (filePath) {
//attach file if specified
var file=new java.io.File(filePath);
var att=tmpDoc.createRichTextItem("Attachment");
att.embedObject(1454, "", filePath, file.getName()); //EmbeddedObject.EMBED_ATTACHMENT
}
tmpDoc.closeMIMEEntities(true)
tmpDoc.save(true,false);
The temporary document now contains all the content that we would like to see in the composed email. We can now use this document as a template for the actual compose operation.
This approach is based on a blog posting of Ryan Baxter:
Creating And Opening A New Notes Document With Some HTML var mailDb=session.getDbDirectory("").openMailDatabase();
ws.composeDocument(mailDb, tmpDoc);
session.setConvertMime(true);
The sample application can be downloaded
here.