ShowTable of Contents
Authors
This button gets all the authors in a database or a subset of a database.
// Open database - get name from user
var db:NotesDatabase = session.getDatabase(null, requestScope.query, false);
if (db == null) {
requestScope.status = "Cannot open " + requestScope.query;
} else {
requestScope.status = "Opened " + requestScope.query;
var limit:int = 0;
var dc:NotesDocumentCollection = db.getAllDocuments();
if (dc.getCount() == 0) {
requestScope.status += "\nNo documents";
return;
}
// Get authors for each document - eliminate duplicates
var doc:NotesDocument = dc.getFirstDocument();
var authorsAll:java.util.Vector = new java.util.Vector();
var authors:java.util.Vector = new java.util.Vector();
while (doc != null) { // append authors to allAuthors
authors = doc.getAuthors();
var ai = authors.iterator();
while (ai.hasNext()) { // remove duplicates
if (authorsAll.contains(ai.next())) {
ai.remove();
}
}
authorsAll.addAll(authors);
authors.clear();
if (++limit > 1024) break; // for big database, just do first 1000
var tmpdoc = dc.getNextDocument();
doc.recycle(); // recycle to avoid memory problems
doc = tmpdoc;
}
// Display each element of the compiled list
ai = authorsAll.iterator();
while (ai.hasNext()) {
requestScope.status += "\n" + ai.next().toString();
}
}
ColumnValues
This list box selection formula returns the values of the first column associated with each document in a view.
var view:NotesView = database.getView("main");
var doc:NotesDocument = view.getFirstDocument();
var list = new Array();
while (doc != null) {
list.push(doc.getColumnValues()[0]);
var tmpdoc = view.getNextDocument(doc);
doc.recycle();
doc = tmpdoc;
}
return list
Created
This computed field gets the difference in days between today and the creation day for the current document.
var today:NotesDateTime = session.createDateTime("Today");
today.setNow();
var created:NotesDateTime = currentDocument.getDocument().getCreated();
var diff = (today.timeDifference(created) / 86400).toFixed(0);
return "This document was created " + diff + " days ago.";
EmbeddedObjects
This computed field displays the names of embedded objects in the document.
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasEmbedded()) {
var eos:java.util.Vector = doc.getEmbeddedObjects();
if (eos.isEmpty()) {
return "Contains attachments"
} else {
var msg:string = "Contains embedded objects:";
var eosi:java.util.Iterator = eos.iterator();
while (eosi.hasNext()) {
var eo:NotesEmbeddedObject = eosi.next();
if (msg.endsWith(":")) {
msg = msg + " ";
} else {
msg = msg + "; ";
}
msg = msg + eo.getName();
}
return msg;
}
} else {
return "No embedded documents"
}
EncryptionKeys
This button adds an encryption key to the current document.
var query:string = requestScope.query;
if (query.isEmpty()) {
requestScope.status = "No key specified";
return;
}
var doc:NotesDocument = currentDocument.getDocument();
var keys:java.util.Vector = doc.getEncryptionKeys();
if (!keys.isEmpty()) {
var keysi = keys.iterator();
while (keysi.hasNext()) {
if (keysi.next().equals(query)) {
requestScope.status = "This key already exists";
return;
}
}
}
keys.addElement(query);
doc.setEncryptionKeys(keys);
doc.save();
requestScope.status = "Key added";
FolderReferences
This computed field displays the folders in which the current document resides. The XPage is in a database based on the mail template.
database.setFolderReferencesEnabled(true); // make sure folder references are enabled
var doc:NotesDocument = currentDocument.getDocument();
var folders = doc.getFolderReferences();
if (folders.isEmpty()) {
return "Not in any folders";
}
var msg = "In these folders:";
var foldersi = folders.iterator();
while (foldersi.hasNext()) {
if (msg.endsWith(":")) {
msg = msg + " ";
} else {
msg = msg + "; ";
}
msg = msg + foldersi.next();
}
return msg;
FTSearchScore
This button gets the search score and subject item from the result of a full-text search.
database.updateFTIndex(true);
var dc:NotesDocumentCollection = database.FTSearch(requestScope.query);
if (dc.getCount() == 0) {
requestScope.status = "No hits";
return;
}
requestScope.status = "Hits:";
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + doc.getFTSearchScore()
+ "\t" + doc.getItemValueString("subject");
// this eats memory!! ==> doc = dc.getNextDocument();
var tmpdoc = dc.getNextDocument();
doc.recycle(); // this releases memory
doc = tmpdoc;
}
HasEmbedded
This computed field displays the names of embedded objects in the document.
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasEmbedded()) {
var eos:java.util.Vector = doc.getEmbeddedObjects();
if (eos.isEmpty()) {
return "Contains attachments"
} else {
var msg:string = "Contains embedded objects:";
var eosi:java.util.Iterator = eos.iterator();
while (eosi.hasNext()) {
var eo:NotesEmbeddedObject = eosi.next();
if (msg.endsWith(":")) {
msg = msg + " ";
} else {
msg = msg + "; ";
}
msg = msg + eo.getName();
}
return msg;
}
} else {
return "No embedded documents"
}
HttpURL
This computed field displays the HTTP URL for server-based applications and the Notes URL for client-based applications.
if (session.isOnServer()) {
return document2.getDocument().getHttpURL();
} else {
return document2.getDocument().getNoteID();
}
InitiallyModified
This computed field displays the creation, initially modified, last modified, and last accessed dates of the current document.
var doc:NotesDocument = currentDocument.getDocument();
var msg = "This document was created on " + doc.getCreated().getDateOnly();
var im:NotesDateTime = doc.getInitiallyModified();
if (im !=null && im != 0) {
var msg = msg + ", initially modified on " + im.getDateOnly();
}
var lm:NotesDateTime = doc.getLastModified();
if (lm != null && im != 0) {
var msg = msg + ", last modified on " + lm.getDateOnly();
}
var la:NotesDateTime = doc.getLastAccessed();
if (la != null && la != 0) {
var msg = msg + ", last accessed on " + la.getDateOnly();
}
return msg
IsDeleted
This button gets the subject item for all documents in the database checking to ensure the documents are valid and not deletion stubs.
var db:NotesDatabase = session.getDatabase("Sales1/Acme", "west\\sales", false);
if (db == null) {
requestScope.status = "Cannot open NotesUA/Westford/Notes//bobtest\\DatabaseEtc";
return;
}
var dc:NotesDocumentCollection = db.getAllDocuments();
if (dc.getCount() == 0) {
requestScope.status = "No documents in database";
return;
}
requestScope.status = "Documents in database:";
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
if (!doc.isValid()) {
var subject = "[document is not valid]";
} else if (doc.isDeleted()) {
subject = "[document is deletion stub]";
} else {
subject = doc.getItemValueString("subject");
}
requestScope.status += "\n" + subject;
var tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
IsEncrypted
This computed field displays the encryption status for the current document.
var doc:NotesDocument = currentDocument.getDocument();
if (doc.isEncrypted()) {
return "This document is encrypted";
} else {
return "This document is not encrypted";
}
IsEncryptOnSend
See
send.
IsNewNote
This computed field returns the save status of the current document.
var doc:NotesDocument = currentDocument.getDocument();
return doc.isNewNote() ? "Document not saved yet" :
"Document last saved at " + doc.getLastModified().getLocalTime();
IsProfile
This computed field displays the name of a profile document if the underlying object is a profile document. The global variable requestScope.doc is set before the document is loaded.
if (requestScope.doc.isProfile()) {
return requestScope.doc.getNameOfProfile();
} else {
return "Not a profile"
}
IsResponse
This computed field displays the response status of the current document.
var doc:NotesDocument = currentDocument.getDocument();
return doc.isResponse() ?
"Response to " + database.getDocumentByUNID(doc.getParentDocumentUNID()).getItemValueString("subject") :
"Main document";
IsSaveMessageOnSend
See send.
IsSentByAgent
This computed field displays whether the current document was sent by a program or a person.
var doc:NotesDocument = currentDocument.getDocument();
if (doc == null) {
return;
}
if (doc.isSentByAgent()) {
return "This document was sent by an agent"
}
IsSigned
This computed field displays the signer and verifier for the current document.
var doc:NotesDocument = currentDocument.getDocument();
return doc.isSigned() ? "Document signed by " + doc.getSigner() +
", verified by " + doc.getVerifier(): "Document not signed;"
IsSignOnSend
See
send.
IsValid
This button gets the subject item for all documents in the database checking to ensure the documents are valid and not deletion stubs.
var db:NotesDatabase = session.getDatabase("Sales1/Acme", "west\\sales", false);
if (db == null) {
requestScope.status = "Cannot open NotesUA/Westford/Notes//bobtest\\DatabaseEtc";
return;
}
var dc:NotesDocumentCollection = db.getAllDocuments();
if (dc.getCount() == 0) {
requestScope.status = "No documents in database";
return;
}
requestScope.status = "Documents in database:";
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
if (!doc.isValid()) {
var subject = "[document is not valid]";
} else if (doc.isDeleted()) {
subject = "[document is deletion stub]";
} else {
subject = doc.getItemValueString("subject");
}
requestScope.status += "\n" + subject;
var tmpdoc = dc.getNextDocument(); doc.recycle(); doc = tmpdoc;
}
Items
This button gets the name and string value of each item in the current document.
try {
var doc:NotesDocument = currentDocument.getDocument();
requestScope.status = "Items in current document:";
var items:java.util.Vector = doc.getItems();
var iterator = items.iterator();
while (iterator.hasNext()) {
var item:NotesItem = iterator.next();
var s = item.getValueString().isEmpty() ? "[No text]" : item.getValueString();
requestScope.status += "\n\n" + item.getName() + "\n" + s;
}
} catch(e) {
requestScope.status += "\n" + e.toString();
}
Key
This computed field displays the name of a profile document and its key if the underlying object is a profile document. The global variable requestScope.doc is set before the document is loaded.
if (sessionScope.doc != null) {
if (sessionScope.doc.isProfile()) {
return sessionScope.doc.getNameOfProfile() + "\n" + sessionScope.doc.getKey();
} else {
return "Not a profile"
}
}
LastAccessed
This computed field displays the creation, initially modified, last modified, and last accessed dates of the current document.
var doc:NotesDocument = currentDocument.getDocument();
var msg = "This document was created on " + doc.getCreated().getDateOnly();
var im:NotesDateTime = doc.getInitiallyModified();
if (im !=null && im != 0) {
var msg = msg + ", initially modified on " + im.getDateOnly();
}
var lm:NotesDateTime = doc.getLastModified();
if (lm != null && im != 0) {
var msg = msg + ", last modified on " + lm.getDateOnly();
}
var la:NotesDateTime = doc.getLastAccessed();
if (la != null && la != 0) {
var msg = msg + ", last accessed on " + la.getDateOnly();
}
return msg
LastModified
This computed field displays the creation, initially modified, last modified, and last accessed dates of the current document.
var doc:NotesDocument = currentDocument.getDocument();
var msg = "This document was created on " + doc.getCreated().getDateOnly();
var im:NotesDateTime = doc.getInitiallyModified();
if (im !=null && im != 0) {
var msg = msg + ", initially modified on " + im.getDateOnly();
}
var lm:NotesDateTime = doc.getLastModified();
if (lm != null && im != 0) {
var msg = msg + ", last modified on " + lm.getDateOnly();
}
var la:NotesDateTime = doc.getLastAccessed();
if (la != null && la != 0) {
var msg = msg + ", last accessed on " + la.getDateOnly();
}
return msg
LockHolders
This computed field displays the lock holders for the current document.
var doc:NotesDocument = currentDocument.getDocument();
var lh:java.util.Vector = doc.getLockHolders();
if (lh.isEmpty()) {
return;
}
var iterator = lh.iterator();
while (iterator.hasNext()) {
var holders:string = iterator.next() + " ";
}
return holders.trim()
NameOfProfile
This computed field displays the name of a profile document if the underlying object is a profile document. The global variable requestScope.doc is set before the document is loaded.
if (requestScope.doc.isProfile()) {
return requestScope.doc.getNameOfProfile();
} else {
return "Not a profile"
}
NoteID
This button gets a document given its Note ID.
try {
var noteid:string = requestScope.query;
if (noteid.startsWith("NT")) { // in case it comes from @NoteID
noteid = noteid.substring(3);
}
var doc:NotesDocument = database.getDocumentByID(noteid);
requestScope.status = doc.getItemValueString("subject");
} catch(e) {
requestScope.status = "Invalid note ID";
}
NotesURL
This computed field displays the HTTP URL for server-based applications and the Notes URL for client-based applications.
if (session.isOnServer()) {
return document2.getDocument().getHttpURL();
} else {
return document2.getDocument().getNoteID();
}
ParentDatabase
This computed field displays the title of the database containing a document made available through a global variable.
var doc:NotesDocument = sessionScope.doc;
if (doc != null) {
return doc.getParentDatabase().getTitle();
}
ParentDocumentUNID
This computed field displays the response status of the current document.
var doc:NotesDocument = currentDocument.getDocument();
return doc.isResponse() ?
"Response to " + database.getDocumentByUNID(doc.getParentDocumentUNID()).getItemValueString("subject") :
"Main document";
ParentView
This computed field displays the title of the view containing a document made available through a global variable.
var doc:NotesDocument = sessionScope.doc;
if (doc != null) {
return doc.getParentDatabase().getTitle();
}
Responses
This button gets all descendants of the current document.
function getResponses(dc:NotesDocumentCollection, tab:string) {
var response = dc.getFirstDocument();
while (response != null) {
requestScope.status += "\n" + tab + response.getItemValueString("subject");
if (response.getResponses().getCount() > 0) {
tab = tab + "\t";
getResponses(response.getResponses(), tab);
tab = tab.left(tab.length - 1);
}
var tmpdoc = dc.getNextDocument();
response.recycle(); // this releases memory
response = tmpdoc;
}
}
try {
var doc:NotesDocument = currentDocument.getDocument();
if (doc.getResponses().getCount() > 0) {
getResponses(doc.getResponses(), "");
} else {
requestScope.status = "No response documents";
}
} catch(e) {
requestScope.status = "No document selected" + e.toString();
}
Signer
This computed field displays the signer and verifier for the current document.
var doc:NotesDocument = currentDocument.getDocument();
return doc.isSigned() ? "Document signed by " + doc.getSigner() +
", verified by " + doc.getVerifier(): "Document not signed;"
Size
This computed field displays the number of bytes in the current document.
var doc:NotesDocument = currentDocument.getDocument();
return "The current document uses " + doc.getSize().toFixed() + " bytes"
UniversalID
This is the XML for a data table. Its returns all documents and the current document (the document for the currently selected row) is accessible through the variable rowdoc. A button in the second column opens a page in edit mode specifying its content with the universal ID of the current document in the table.
<xp:dataTable id="dataTable1" rows="30" value="#{javascript:return database.getAllDocuments()}" var="rowdoc">
<xp:column id="column1">
<xp:text escape="true" id="computedField3"><xp:this.value>
<![CDATA[#{javascript:return rowdoc.getItemValueString("subject")}]]></xp:this.value></xp:text>
<xp:this.facets><xp:label value="subject" id="label1" xp:key="header"></xp:label></xp:this.facets>
</xp:column>
<xp:column id="column2">
<xp:button value="edit" id="button6"><xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<xp:openPage name="/main2.xsp" target="editDocument"
documentId="#{javascript:rowdoc.getUniversalID()}">
</xp:openPage>
</xp:this.action></xp:eventHandler></xp:button>
</xp:column>
</xp:dataTable>
Verifier
This computed field displays the signer and verifier for the current document.
var doc:NotesDocument = currentDocument.getDocument();
return doc.isSigned() ? "Document signed by " + doc.getSigner() +
", verified by " + doc.getVerifier(): "Document not signed;"
appendItemValue
This button creates a new document in the current database and appends an item named Subject with the value of a requestScope variable. The requestScope variable is bound to an edit box that the user fills in before clicking the button.
var doc = database.createDocument();
doc.appendItemValue("Subject", requestScope.subject);
doc.save()
attachVCard
This button attaches vCards to a memo before mailing.
try {
// requestScope.sendto is a list box allowing multiple entries - returns java.util.ArrayList
// stop processing if sendto is empty
if (requestScope.sendto.isEmpty()) {
requestScope.status = "No sender(s) specified";
return;
}
var sendto = new java.util.Vector(requestScope.sendto);
var memo:NotesDocument = database.createDocument();
memo.appendItemValue("Form", "Memo");
// requestScope.subject is an edit box - returns string
memo.appendItemValue("Subject", requestScope.subject);
// requestScope.body is rich text - returns com.ibm.xsp.http.MimeMultipart
// do not create mime entity if body is null
if (requestScope.body != null) {
// stream html from body to mime entity
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText(requestScope.body.getHTML());
var body = memo.createMIMEEntity("Body");
body.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
stream.close();
memo.closeMIMEEntities(true);
session.setConvertMime(true);
}
// Attach vcards that contain requestScope.query (edit box)
var names:NotesDatabase = session.getDatabase(null, "names", false);
if (names != null) {
var view:NotesView = names.getView("My Contacts");
if (view.FTSearch(requestScope.query) > 0) {
var doc:NotesDocument = view.getFirstDocument();
while (doc != null) {
memo.attachVCard(doc);
var tmpdoc = view.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
}
}
// send memo and report status
memo.send(false, sendto); // same as memo.send(sendto);
requestScope.status = "Message sent\n";
} catch(e) {
requestScope.status = e.toString();
}
closeMIMEEntities
See
send.
computeWithForm
The following button verifies a new document against the “main“ form before saving.
var doc = database.createDocument();
doc.appendItemValue("Form", "main");
doc.appendItemValue("Subject", requestScope.query);
if (doc.computeWithForm(false, false)) {
doc.save();
requestScope.status = "Document saved";
} else {
requestScope.status = "Input verification failed";
}
converttomime
This button mails a document in MIME format.
try {
// requestScope.sendto is a list box allowing multiple entries - returns java.util.ArrayList
// stop processing if sendto is empty
if (requestScope.sendto.isEmpty()) {
requestScope.status = "No sender(s) specified";
return;
}
var sendto = new java.util.Vector(requestScope.sendto);
var memo:NotesDocument = database.createDocument();memo.con
memo.appendItemValue("Form", "Memo");
// requestScope.subject is an edit box - returns string
memo.appendItemValue("Subject", requestScope.subject);
// requestScope.body is rich text - returns com.ibm.xsp.http.MimeMultipart
// do not create mime entity if body is null
if (requestScope.body != null) {
// stream html from body to mime entity
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText(requestScope.body.getHTML());
var body = memo.createMIMEEntity("Body");
body.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
stream.close();
memo.closeMIMEEntities(true);
session.setConvertMime(true);
}
// send memo and report status
memo.convertToMIME(NotesDocument.CVT_RT_TO_HTML);
memo.send(false, sendto); // same as memo.send(sendto);
requestScope.status = "Message sent\n";
} catch(e) {
requestScope.status = e.toString();
}
copyAllItems
This button creates a document and a copy.
var doc = database.createDocument();
doc.appendItemValue("Form", "main");
doc.appendItemValue("Subject", requestScope.query);
doc.appendItemValue("Quantity", requestScope.quantity);
doc.save();
var copy = database.createDocument();
doc.copyAllItems(copy, false);
copy.replaceItemValue("subject", "Copy of " + copy.getItemValueString("subject"));
copy.save();
requestScope.status = "Document and copy created"
copyItem
This button creates a new document copying into it an item from a profile document.
var doc:NotesDocument = database.createDocument();
var disclaimer:NotesDocument = database.getProfileDocument("Disclaimer", null);
var text:NotesItem = disclaimer.getFirstItem("DisclaimerText");
doc.appendItemValue("Form", "main");
doc.appendItemValue("Subject", requestScope.query);
doc.appendItemValue("Quantity", requestScope.quantity);
var foo = doc.copyItem(text);
doc.save();
requestScope.status = "Document created";
copyToDatabase
This button creates an archive of the main view in the current database.
try {
var newdb:NotesDatabase = database.createCopy(null, + "archive_" + database.getFileName());
} catch(e) {
requestScope.status = "Error: cannot create archive";
return;
}
newdb.setTitle("Copy of " + database.getTitle());
requestScope.status = "Archive created\n";
var view:NotesView = database.getView("main");
var doc:NotesDocument = view.getFirstDocument();
var count:int = 0;
while (doc != null) {
doc.copyToDatabase(newdb);
count++;
var tmpdoc = view.getNextDocument(doc);
doc.recycle();
doc = tmpdoc;
}
requestScope.status += count + " documents copied to archive";
createMIMEEntity
This button mails a document in MIME format.
var stream:NotesStream = session.createStream();
session.setConvertMime(false); // do not convert mime to rich text
var doc:NotesDocument = database.createDocument();
doc.appendItemValue("Form", "Memo");
var body:NotesMIMEEntity = doc.createMIMEEntity();
var header:NotesMIMEHeader = body.createHeader("Subject");
if (!header.setHeaderVal("MIME message")) {
requestScope.status = "Cannot set header val for Subject";
return;
}
header = body.createHeader("To");
if (!header.setHeaderVal("Robert Perron")) {
requestScope.status = "Cannot set header val for To";
return;
}
stream.writeText("This is the text of the message.");
body.setContentFromText(stream, "text/plain;charset=UTF-8", NotesMIMEEntity.ENC_NONE);
doc.send();
session.setConvertMime(true); // restore coversion
Also see
send.
createReplyMessage
This button sends a reply message for each document in a mail folder.
try {
var dbdir:NotesDbDirectory = session.getDbDirectory(null);
var db:NotesDatabase = dbdir.openMailDatabase();
requestScope.status = db.getTitle() + " on " + db.getServer() + " is " + (db.isOpen() ? "open" : "not open");
var view:NotesView = db.getView("FiledButNotForgotten");
if (view == null) {
requestScope.status += "\nCould not open folder";
return;
}
requestScope.status += "\nOpened folder " + view.getName();
var doc:NotesDocument = view.getFirstDocument();
while (doc != null) {
var reply:NotesDocument = doc.createReplyMessage(false);
var subject = doc.getItemValueString("Subject");
reply.replaceItemValue("Subject", "\nCan't work on this now: " + subject);
reply.replaceItemValue("Body", "This has been filed for future consideration.");
reply.send();
requestScope.status += "\nreplied to " + subject;
var tmpdoc = view.getNextDocument(doc);
doc.recycle();
doc = tmpdoc;
}
} catch(e) {
requestScope.status += e.toString();
}
createRichTextItem
This button creates a new document in the current database with a rich text item containing text and an attachment.
try {
var doc:NotesDocument = database.createDocument();
doc.appendItemValue("Form", "main");
var image:string = requestScope.query;
doc.appendItemValue("Subject", image);
var rtitem:NotesRichTextItem = doc.createRichTextItem("Body");
rtitem.appendText("Attached is " + image + ".");
rtitem.addNewLine();
rtitem.embedObject(NotesEmbeddedObject.EMBED_ATTACHMENT, "", image, null);
doc.save();
requestScope.status = "Created document for image " + image;
} catch(e) {
requestScope.status = "Could not create document for image " + image;
}
encrypt
This button encrypts the current document.
var doc:NotesDocument = currentDocument.getDocument();
if (!doc.isEncrypted()) {
doc.encrypt();
doc.save()
}
generateXML
This button creates a document, generates an XML representation of the document, and writes the result to a file.
try {
var doc:NotesDocument = database.createDocument();
doc.appendItemValue("Form", "main");
doc.appendItemValue("Subject", requestScope.query);
doc.appendItemValue("Quantity", requestScope.quantity);
var bw:java.io.BufferedWriter = new java.io.BufferedWriter(new
java.io.FileWriter("c:\\temp\\document.xml"));
doc.generateXML(bw);
bw.close();
requestScope.status = "XML document written to c:\\temp";
} catch(e) {
requestScope.status = e.toString();
}
getAttachment
This button searches the documents in the current database for a specified attachment.
try {
var dc:NotesDocumentCollection = database.getAllDocuments();
var doc:NotesDocument = NotesDocument = dc.getFirstDocument();
while (doc != null) {
var obj:NotesEmbeddedObject = doc.getAttachment(requestScope.query);
if (obj != null) {
requestScope.status = "Found " + obj.getName() + " in \"" +
doc.getItemValueString("Subject") + "\"";
break;
}
var tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;}
if (!requestScope.status.startsWith("Found")) {
requestScope.status += "\nDid not find attachment"
}
} catch(e) {
requestScope.status = e.toString();
}
getFirstItem
This button dumps information from all the documents in the current database.
try {
var dc:NotesDocumentCollection = database.getAllDocuments();
var doc:NotesDocument = dc.getFirstDocument();
while (doc != null) {
var subject:NotesItem = doc.getFirstItem("Subject");
if (subject == null) {
requestScope.status += "\n[ No subject ]";
} else {
requestScope.status += "\n[ " + subject.getText() + " ]";
}
var body:NotesItem = doc.getFirstItem("Body");
if (body == null) {
requestScope.status += "\n[ No body ]";
} else {
var text:string = body.getText(256);
requestScope.status += "\n" + text;
}
var tmpdoc = dc.getNextDocument();
doc.recycle();
doc = tmpdoc;
}
} catch(e) {
requestScope.status = e.toString();
}
getItemValue
This button gets the value or values of an item in the current document. The user specifies the item name. The button determines the item type and gets values accordingly.
try {
var itemname:string = requestScope.query;
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem(itemname)) {
var itemvalues:java.util.Vector = doc.getItemValue(itemname);
var iterator = itemvalues.iterator();
while (iterator.hasNext()) {
var itemvalue = iterator.next();
if ((typeof(itemvalue)).endsWith("string")) {
requestScope.status += "\n" + itemvalue.left(80);
} else if ((typeof(itemvalue)).endsWith("number")) {
requestScope.status += "\n" + itemvalue.toFixed();
} else if ((typeof(itemvalue)).endsWith("DateTime")) {
requestScope.status += "\n" + itemvalue.getLocalTime();
}
}
}
} catch(e) {
requestScope.status += "\n" + e.toString();
}
getItemValueDateTimeArray
This button gets the value of a date-time item in the current document.
try {
var itemname:string = "times";
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem(itemname)) {
var itemvalue:java.util.Vector = doc.getItemValueDateTimeArray(itemname);
var iterator = itemvalue.iterator();
while (iterator.hasNext()) {
var itemvalue1 = iterator.next();
if ((typeof(itemvalue1)).endsWith("DateTime")) {
requestScope.status += "\nTime: " + itemvalue1.getLocalTime();
} else if ((typeof(itemvalue1)).endsWith("DateRange")) {
requestScope.status += "\nStart: " + itemvalue1.getStartDateTime().getLocalTime();
requestScope.status += "\nEnd: " + itemvalue1.getEndDateTime().getLocalTime();
}
}
}
} catch(e) {
requestScope.status += "\n" + e.toString()
}
getItemValueDouble
This button gets the value of a numeric item in the current document as a double.
var itemname:string = "distance";
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem(itemname)) {
var itemvalue:double = doc.getItemValueDouble(itemname);
requestScope.status = itemvalue.toFixed();
}
getItemValueInteger
This button gets the value of a numeric item in the current document as an integer.
var itemname:string = "quantity";
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem(itemname)) {
var itemvalue:int = doc.getItemValueInteger(itemname);
requestScope.status = itemvalue.toFixed();
}
getItemValueString
This button gets the value of a string item in the current document.
var itemname:string = "subject";
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem(itemname)) {
var itemvalue:string = doc.getItemValueString(itemname);
if (itemvalue.length > 0) {
requestScope.status = itemvalue;
} else {
requestScope.status = itemname + " is empty or not a string"
}
} else {
requestScope.status = itemname + " does not exist";
}
getMIMEEntity
This button gets the MIME content from the current document.
var doc:NotesDocument = currentDocument.getDocument();
var mime:NotesMIMEEntity = doc.getMIMEEntity();
if (mime != null) {
var m:string = "Content type: " + mime.getContentType() + "\n" +
"Content subtype: " + mime.getContentSubType() + "\n" +
"Character set: " + mime.getCharset() + "\n" +
"Encoding: " + mime.getEncoding();
requestScope.status = doc.getItemValueString("Subject") + "\n" + m + "\n" +
mime.getHeaders() + "\n" + mime.getContentAsText();
} else {
requestScope.status = "Not MIME - " + doc.getItemValueString("Subject");
}
getRead
This button reports whether a user has read the documents in a view in the current database.
try {
var username:string = requestScope.query; // edit box
var view:NotesView = database.getView("main");
var doc = view.getFirstDocument();
while (doc != null) {
requestScope.status += "\n" + username +
((doc.getRead(username)) ? " has " : " has not ") + "read " + doc.getItemValueString("subject");
var tmpdoc = view.getNextDocument(doc);
doc.recycle();
doc = tmpdoc;
}
} catch(e) {
requestScope.status += "\n" + e.toString();
}
getReceivedItemText
This button gets all the Received items in the current document.
try {
var doc:NotesDocument = currentDocument.getDocument();
var rit:java.util.Vector = doc.getReceivedItemText();
if (rit.isEmpty()) {
requestScope.status = "No Received items";
} else {
requestScope.status = "Received items";
var iterator = rit.iterator();
while (iterator.hasNext()) {
requestScope.status += "\n\n" + iterator.next();
}
}
} catch(e) {
requestScope.status += "\n" + e.toString();
}
getURL
This computed field displays the URL to open the current document.
var doc:NotesDocument = currentDocument.getDocument();
return "The URL to open this document is " + doc.getURL()
hasItem
This button tells the user whether a specified item exists in the current document.
var itemname:string = requestScope.query; // input box
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem(itemname)) {
requestScope.status = "The current document has an item named " + itemname;
} else {
requestScope.status = "The current document does not have an item named " + itemname;
}
lock
This button locks the current document for the current user.
try {
var doc:NotesDocument = currentDocument.getDocument();
if (!database.isDocumentLockingEnabled()) {
database.setDocumentLockingEnabled(true);
}
if (doc.lock(session.getEffectiveUserName(), true)) {
requestScope.status = "Document locked";
} else {
requestScope.status = "Document not locked";
}
} catch(e) {
requestScope.status = "Document not locked";
}
lockProvisional
This button locks the current document for the current user.
try {
var doc:NotesDocument = currentDocument.getDocument();
if (!database.isDocumentLockingEnabled()) {
database.setDocumentLockingEnabled(true);
}
if (doc.lockProvisional()) {
requestScope.status = "Document locked";
} else {
requestScope.status = "Document not locked";
}
} catch(e) {
requestScope.status = "Document not locked";
}
makeResponse
This button creates a response to the current document.
var doc:NotesDocument = currentDocument.getDocument();
var rdoc:NotesDocument = database.createDocument();
rdoc.appendItemValue("Form", "response");
rdoc.appendItemValue("Subject", session.getCommonUserName() + " has read this document<>");
rdoc.makeResponse(doc);
if (rdoc.save()) {
requestScope.status = "Response posted"
} else {
requestScope.status = "Unable to save response"
}
markRead
This button marks the current document as read.
var doc:NotesDocument = currentDocument.getDocument();
var rdoc:NotesDocument = database.createDocument();
rdoc.appendItemValue("Form", "response");
rdoc.appendItemValue("Subject", session.getCommonUserName() + " has read this document<>");
rdoc.makeResponse(doc);
doc.markRead();
if (rdoc.save()) {
requestScope.status = "Response posted and document marked read";
} else {
requestScope.status = "Unable to save response";
}
markUnread
This button marks the current document as unread.
var doc:NotesDocument = currentDocument.getDocument();
var rdoc:NotesDocument = database.createDocument();
rdoc.appendItemValue("Form", "response");
rdoc.appendItemValue("Subject", session.getCommonUserName() + " needs to look at this further<>");
rdoc.makeResponse(doc);
doc.markUnread();
if (rdoc.save()) {
requestScope.status = "Response posted and document marked unread";
} else {
requestScope.status = "Unable to save response";
}
putInFolder
This button puts the current document into a folder specified by the user.
var doc:NotesDocument = currentDocument.getDocument();
if (doc != null) {
doc.putInFolder(requestScope.folder); // folder is bound to an edit box
}
remove
This button removes all the documents in a folder.
var view:NotesView = database.getView("oldstuff");
var doc:NotesDocument = view.getFirstDocument();
while (doc != null) {
var subject:string = doc.getItemValueString("Subject");
doc.remove(true);
requestScope.status += "\n\"" + subject + "\" removed";
doc = view.getFirstDocument();
}
removeFromFolder
This button removes the current document from a user-specified folder.
var doc:NotesDocument = currentDocument.getDocument();
if (doc != null) {
doc.removeFromFolder(requestScope.folder);
}
removeItem
This button removes an item from the current document.
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem("quantity")) {
doc.removeItem("quantity");
if (doc.save()) {
requestScope.status = "Quantity item removed";
} else {
requestScope.status = "Save failed";
}
} else {
requestScope.status = "Document does not have quantity item";
}
removePermanently
This button removes all the documents in a folder.
var view:NotesView = database.getView("oldstuff");
var doc:NotesDocument = view.getFirstDocument();
while (doc != null) {
var subject:string = doc.getItemValueString("Subject");
doc.removePermanently(true);
requestScope.status += "\n\"" + subject + "\" removed";
doc = view.getFirstDocument();
}
renderToRTItem
This button sends a memo containing a rendering of the current document.
var doc:NotesDocument = currentDocument.getDocument();
var memo:NotesDocument = database.createDocument();
memo.appendItemValue("Form", "memo");
memo.appendItemValue("Subject", "Picture of " + doc.getItemValueString("subject"));
var body:NotesRichTextItem = memo.createRichTextItem("Body");
memo.save();
doc.renderToRTItem(body);
memo.send(session.getUserName());
replaceItemValue
This button adds a value to a numeric multi-value item in the current document.
var doc:NotesDocument = currentDocument.getDocument();
if (doc.hasItem("quantity")) {
var quantities:java.util.Vector = doc.getItemValue("quantity");
if (quantities.add(requestScope.queryn)) {
doc.replaceItemValue("quantity", quantities);
doc.save();
requestScope.status = "Quantity item replaced";
} else {
requestScope.status = "Unable to replace quantity item";
}
} else {
doc.appendItemValue("quantity", requestScope.queryn);
doc.save();
requestScope.status = "New quantity item added";
}
save
This button creates a new document in the current database and appends an item named Subject with the value of a requestScope variable. The requestScope variable is bound to an edit box that the user fills in before clicking the button.
var doc = database.createDocument();
doc.appendItemValue("Subject", requestScope.subject);
doc.save()
send
This button creates and mails a document collecting recipients, subject, and options from scoped variables on the current XPage.
try {
// requestScope.sendto is a list box allowing multiple entries - returns java.util.ArrayList
// stop processing if sendto is empty
if (requestScope.sendto.isEmpty()) {
requestScope.status = "No sender(s) specified";
return;
}
var sendto = new java.util.Vector(requestScope.sendto);
var memo:NotesDocument = database.createDocument();
memo.appendItemValue("Form", "Memo");
// requestScope.subject is an edit box - returns string
memo.appendItemValue("Subject", requestScope.subject);
// requestScope.body is rich text - returns com.ibm.xsp.http.MimeMultipart
// do not create mime entity if body is null
if (requestScope.body != null) {
// stream html from body to mime entity
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText(requestScope.body.getHTML());
var body = memo.createMIMEEntity("Body");
body.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
stream.close();
memo.closeMIMEEntities(true);
session.setConvertMime(true);
}
// set mail options
var items = memo.getItems(); // hack: encrypted and signed memo fails without this
memo.setEncryptOnSend(sessionScope.encrypt); // sessionScope.encrypt set by button
memo.setSignOnSend(sessionScope.sign); // sessionScope.sign set by button
memo.setSaveMessageOnSend(sessionScope.sos); // sessionScope.sos set by button
// send memo and report status
memo.send(false, sendto); // same as memo.send(sendto);
requestScope.status = "Message sent\n";
requestScope.status +=
"Memo is " + (memo.isSaveMessageOnSend() ? "saved\n" : "not saved\n");
requestScope.status +=
"Memo is " + (memo.isEncryptOnSend() ? "encrypted\n" : "not encrypted\n");
requestScope.status +=
"Memo is " + (memo.isSignOnSend() ? "signed\n" : "not signed");
} catch(e) {
requestScope.status = e.toString();
}
Here is the XML for the entire XPage.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.afterPageLoad><![CDATA[#{javascript:sessionScope.sos = false;
sessionScope.encrypt = false;
sessionScope.sign = false}]]></xp:this.afterPageLoad>
<xp:listBox id="listBox1" multiple="true" value="#{requestScope.sendto}">
<xp:selectItem itemLabel="Roberta Person/Acme"></xp:selectItem>
<xp:selectItem itemLabel="John Smith/Acme"></xp:selectItem>
<xp:selectItem itemLabel="Jane Brown/Acme"></xp:selectItem>
</xp:listBox>
<xp:br></xp:br>
<xp:inputText id="inputText1" value="#{requestScope.subject}"></xp:inputText>
<xp:button id="button1" value="send">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:try {
// requestScope.sendto is a list box allowing multiple entries - returns java.util.ArrayList
// stop processing if sendto is empty
if (requestScope.sendto.isEmpty()) {
requestScope.status = "No sender(s) specified";
return;
}
var sendto = new java.util.Vector(requestScope.sendto);
var memo:NotesDocument = database.createDocument();
memo.appendItemValue("Form", "Memo");
// requestScope.subject is an edit box - returns string
memo.appendItemValue("Subject", requestScope.subject);
// requestScope.body is rich text - returns com.ibm.xsp.http.MimeMultipart
// do not create mime entity if body is null
if (requestScope.body != null) {
// stream html from body to mime entity
session.setConvertMime(false);
var stream = session.createStream();
stream.writeText(requestScope.body.getHTML());
var body = memo.createMIMEEntity("Body");
body.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
stream.close();
memo.closeMIMEEntities(true);
session.setConvertMime(true);
}
// set mail options
var items = memo.getItems(); // hack: encrypted and signed memo fails without this
memo.setEncryptOnSend(sessionScope.encrypt); // sessionScope.encrypt set by button
memo.setSignOnSend(sessionScope.sign); // sessionScope.sign set by button
memo.setSaveMessageOnSend(sessionScope.sos); // sessionScope.sos set by button
// send memo and report status
memo.send(false, sendto); // same as memo.send(sendto);
requestScope.status = "Message sent\n";
requestScope.status +=
"Memo is " + (memo.isSaveMessageOnSend() ? "saved\n" : "not saved\n");
requestScope.status +=
"Memo is " + (memo.isEncryptOnSend() ? "encrypted\n" : "not encrypted\n");
requestScope.status +=
"Memo is " + (memo.isSignOnSend() ? "signed\n" : "not signed");
} catch(e) {
requestScope.status = e.toString();
}}]]></xp:this.action>
</xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button id="button2"><xp:this.value><![CDATA[#{javascript:if (sessionScope.sos) {
return "Save on send"
} else {
return "Do not save on send"
}}]]></xp:this.value>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="button2">
<xp:this.action><![CDATA[#{javascript:if (sessionScope.sos) {
sessionScope.sos = false;
} else {
sessionScope.sos = true;
}}]]></xp:this.action>
</xp:eventHandler></xp:button>
<xp:button id="button3"><xp:this.value><![CDATA[#{javascript:if (sessionScope.encrypt) {
return "Encrypt on send"
} else {
return "Do not encrypt on send"
}}]]></xp:this.value>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="button3">
<xp:this.action><![CDATA[#{javascript:if (sessionScope.encrypt) {
sessionScope.encrypt = false;
} else {
sessionScope.encrypt = true;
}}]]></xp:this.action>
</xp:eventHandler></xp:button><xp:button id="button4"><xp:this.value><![CDATA[#{javascript:if (sessionScope.sign) {
return "Sign on send"
} else {
return "Do not sign on send"
}}]]></xp:this.value>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="button4">
<xp:this.action><![CDATA[#{javascript:if (sessionScope.sign) {
sessionScope.sign = false;
} else {
sessionScope.sign = true;
}}]]></xp:this.action>
</xp:eventHandler></xp:button><xp:br></xp:br>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:inputRichText id="inputRichText1" value="#{requestScope.body}"
style="height:148.0px;width:456.0px">
</xp:inputRichText>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:inputTextarea id="inputTextarea1" style="width:456.0px" value="#{requestScope.status}"></xp:inputTextarea><xp:br></xp:br>
</xp:view>
sign
This button creates a new document and signs it.
var doc:NotesDocument = database.createDocument();
doc.appendItemValue("Form", "main");
doc.appendItemValue("subject", requestScope.query);
doc.sign();
doc.save();
requestScope.status = "Document signed by " + doc.getSigner();
requestScope.status += "\nDocument verified by " + doc.getVerifier();
unlock
This button unlocks the current document.
try {
var doc:NotesDocument = currentDocument.getDocument();
doc.unlock();
requestScope.status = "Document unlocked";
} catch(e) {
requestScope.status = "Document not unlocked";
}