attachVCard (NotesDocument - JavaScript)

Attaches one or more documents in vCard format.

Defined in

NotesDocument

Syntax

attachVCard(base:NotesBase) : void

attachVCard(base:NotesBase, filename:string) : void

Parameter Description
base NotesDocument, NotesDocumentCollection, or NotesNoteCollection. The Contact document or documents to be attached in vCard format. If a collection is specified, a single attachment will be made with the individual vCards lying end to end.
filename The filename of the Contact document or documents to be attached in vCard format.

Usage

To keep the new attachment in the document, you must call save after calling this method.

If an empty collection is supplied, the error "No documents in collection" occurs.

If the documents are not Contact documents, the documents will not be attached, and the error "Attach of VCard failed" occurs.

The attachment are in the UTF-8 character set.

Examples

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(); // recycle to avoid memory problems
			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();
}