getNamedDocument (Database - Java)

Returns a named document.

Note: This method is new in R12.0.1.

Defined in

Database

Syntax

Document getNamedDocument( String Name )
Document getNamedDocument( String Name, String UserName)

Parameters

name username

String. Specifies the name of a named document. Can be followed by an optional user name to associate a user with the named document.

Usage

Returns a named document, a type of document that has a name rather than a NoteID and does not appear in the Notes client or in any view. A named document is designed for programmatic access and is a functional replacement for profile documents used previously.

If a named document of the specified name is not found, it is created. The Document property IsNewNote returns True if the document is created or False if it existed previously.

An optional username qualifier can be added to be used as a data store for that user.

A named document cannot have a period (.) in its name.

Example

Session s = getSession();
AgentContext ac = s.getAgentContext();

// (Your code goes here) 
int ct = 0;
Database db = s.getCurrentDatabase();
Document gdoc = db.getNamedDocument("MyNamedDoc7");
if (gdoc != null) ct = ct + 1;
System.out.println("id: " + gdoc.getNoteID() + "  " + gdoc.getNameOfDoc() + " uname: " + gdoc.getUserNameOfDoc()  + " new: " + String.valueOf(gdoc.isNewNote()));
gdoc.recycle();
		
gdoc = db.getNamedDocument("MyNamedDoc7", "John Doe");
if (gdoc != null) ct = ct + 1;
System.out.println("id: " + gdoc.getNoteID() + "  " + gdoc.getNameOfDoc() + " uname: " + gdoc.getUserNameOfDoc()  + " new: " + String.valueOf(gdoc.isNewNote()));
gdoc.recycle();
		
gdoc = db.getNamedDocument("MyNamedDoc8");
if (gdoc != null) ct = ct + 1;
System.out.println("id: " + gdoc.getNoteID() + "  " + gdoc.getNameOfDoc() + " uname: " + gdoc.getUserNameOfDoc()  + " new: " + String.valueOf(gdoc.isNewNote()));
gdoc.recycle();
		
gdoc = db.getNamedDocument("MyNamedDoc8", "John Doe");
if (gdoc != null) ct = ct + 1;
System.out.println("id: " + gdoc.getNoteID() + "  " + gdoc.getNameOfDoc() + " uname: " + gdoc.getUserNameOfDoc()  + " new: " + String.valueOf(gdoc.isNewNote()));
gdoc.recycle();
		
DocumentCollection dc = db.getNamedDocumentCollection();
ct = dc.getCount();
System.out.println("Collection: " + ct);
Document doc = dc.getFirstDocument();
Document tmpdoc;

while (doc != null)
	{
	System.out.println("id: " + doc.getNoteID() + "  name: " + doc.getNameOfDoc() + "  uname: " + doc.getUserNameOfDoc() + "  isNew: " + String.valueOf(doc.isNewNote()));	
	tmpdoc = dc.getNextDocument(doc);
	doc.recycle();
	doc = tmpdoc;	
	}
	
dc = db.getNamedDocumentCollection("MyCollGhost8");	/* should be only two */
ct = dc.getCount();

System.out.println("Filtered Collection: " + ct);
doc = dc.getFirstDocument();

while (doc != null)
	{
	System.out.println("id: " + doc.getNoteID() + "  name: " + doc.getNameOfDoc() + "  uname: " + doc.getUserNameOfDoc() + "  isNew: " + 				String.valueOf(doc.isNewNote()));	
	tmpdoc = dc.getNextDocument(doc);
	doc.recycle();
	doc = tmpdoc;	
	}
	
} catch(Exception e) {
	e.printStackTrace();
	}
}