Lotus Domino / Notes is an enterprise communication and group service platform out of the US Lotus Company. However, due to its restrictions on the development tools provided by itself, it is very difficult to implement system-level functions in Notes. For example, in Notes, the number and content of the unread document of a database cannot be obtained by formula or script. However, the small function of this unread document is very useful in some aspects, for example, we can make a reminder function according to this unread document, remind the user that certain types of work such as file issuance. The Notes system itself has a Minder program, which is a new message to remind the user and provide some basic information: to the man, title, etc. We can also do this (of course, using unread documents is not perfect, if you are interested, you can try to be a database hook program to achieve, but in general, the number of unread documents is simpler. ).
This article is to discuss how to use the C API provided by Notes to implement the unread document and its information of a Notes database. Because of the use of C API, our development language is C. Development tools we choose VC 6.0. We need to use the C API function provided by Notes itself. Most of the APIs in Notes are encapsulated in nnotes.dll files. These include API functions in all aspects of ACL, Database, User, Document, Item. It is not light energy to achieve almost all features implemented in Notes, and it also provides other features that are unimaginable in Notes (in other words, you can write your own unique Notes desktop programs without using notes.exe. Of course it The function is far more than this). Using the Notes API package, we can do the following procedures:
1. Independent application.
2, Domino server extension insertion service (add -in task).
3. Menu add-inside the Notes client.
4, Notes clients can dynamically load the library.
5. The hook driver of the database.
6. Extend the hook function library of the management program.
7. Drivers for non-Notes databases.
Let's take a brief introduction to the main Notes API function we will involve:
NotesiniteXtended: Initialize the Notes environment, you should initialize the system before all Notes API functions.
NSFDBopen: Open the specified Notes database.
NSFDBClose: Turn off the specified Notes database.
NSFDBGETUNREADNOTABLE: A list of unread documents within the specified database.
NSFDBUPDATEUNREAD: Updates the list of unread documents for the database.
NiffIndView: Get the specified view or folder within the database.
NiFopencollection: All documents for specifying views or folders.
NifupDateCollection: Update all documents for the specified view or folder.
NifClosecollection: Close the document set.
Nifreadentries: Read the specified documentation of the text set.
NSFNoteopen: Open the specified document.
NSFITEMGETTEXT: Take the specified field value of the document.
Procedure flow chart:
There is a list of unread documents for IDTable in the database, which contains document numbers with unread flags. This table is stored in the database and the client's Desktop.dsk file. Of course, this table in the database and file is the same. When they are inconsistent, they will automatically synchronize when you open the database, so they keep them.
We are to get this unread document table, and then count how many items in this table, know how many documents in the database have unread flags. We can also obtain some specific information about this document on this basis. But this table is a list of unread documents of the entire database. How do we get unread text and information about a view or folder? In fact, this is what we really care. We can find a list of documents and folders, and then make one more compared to the unread document list above, the same is the unread document list of this view or folder. The main procedures are as follows:
////ITNOTES: Initialize the Notes environment, open the database // szServerName: server name // szdbname: Database name // szdirectory: Notes system directory // Return value: 1 - Success / 0 - failed
Int CNOTES :: INITNOTES (Char * SZSERVERNAME, CHAR * SZDBNAME, CHAR * SZDIRECTORY)
{
STATUS STATUS;
CHAR SZPATHNAME [MAX_PATH];
Char szpinitpara [1] [260];
// Database path name = server name "!!" database name
IF (Strlen (SZServerName) == 0)
Strcpy (szpathname, szdbname);
Else {
STRCPY (SZPathname, SZServerName);
STRCAT (SZPATHNAME, "!!");
Strcat (szpathname, szdbname);
}
Strcpy (Szpinitpara [0], SZDIRECTORY);
IF (! m_bopened)
NotesiniteXtended (1, (char **) szpinitpara); // Initialize the Notes environment
Status = nsfdbopen (szpathname, & hdb); // Open the database
IF (status! = noerror) {
m_bopened = false;
Return 0;
}
m_bopened = true;
Return 1;
}
///// getUnread: Number of unread documents in the specified view or folder // szViewName: view or folder name // return value: -1 - Fail // Other - Unread document
INT CNOTES :: getRead (Char * SzViewName)
{
STATUS STATUS;
Char szusername [MAX_PATH];
Status = seckfmgetusername (szusername); // Get the current username
IF (status! = noerror) {
M_BgetunRead = false;
Return -1;
}
Status = nsfdbgetunreadNotetable (HDB, SzuserName, _Strlen (SzuserName), true, & htable; // Take a list of unread documents for the database
IF (status! = noerror) {
M_BgetunRead = false;
Return -1;
}
IF (htable == null) {
M_BgetunRead = false;
Return -1;
}
Status = nsfdbupdateunread (HDB, HTABLE); // Update an unread document list
IF (status! = noerror) {
Osmemfree (HTABLE);
M_BgetunRead = false;
Return -1;
Status = NiffIndView (HDB, SzViewName, & ViewID); File: / / Get a view or folder of the database
IF (status! = noerror) {
Osmemfree (HTABLE);
M_BgetunRead = false;
Return -1;
}
Status = NiFopencollection (HDB, HDB, Viewid, 0, HTable, _ & Hcollection, NULL, NULL, NULL, NULL);
IF (status! = noerror) {
Osmemfree (HTABLE);
M_BgetunRead = false;
Return -1;
}
Status = NifuPdateCollection (HCOLLECTION);
IF (status! = noerror) {
NifClosecollection (hcollection);
Osmemfree (HTABLE);
M_BgetunRead = false;
Return -1;
}
CollectionPosition COLLPSITION;
Collposition.Level = 0;
CollPosition.Tumbler [0] = 0;
Handle Hbuffer;
DWORD NOTESFOUND;
Word signalflags;
Status = Nifreadentries (Hcollection, & Collposition, _navigate_next, 1L, navigate_next, 0xfff, read_mask_noteid, _ & hbuffer, null, null, & notesfound, & signalflags);
IF (status! = noerror) {
NifClosecollection (hcollection);
Osmemfree (HTABLE);
M_BgetunRead = false;
Return -1;
}
INT iViewunread = 0;
Noteid noteId;
BOOL FFIRST = TRUE;
Unsigned Int i;
Noteid * idlist;
IF (hbuffer! = nullhandle)
{
Idlist = (Noteid Far *) OslockObject (HBuffer);
While (Idscan (Htable, Ffirst, & Noteid) // Sequently get the document number in the HTABLE table
{
Ffirst = false;
For (i = 0; i
IF (Noteid == Idlist [i]) {
iViewunRead ;
Break;
}
}
OsunlockObject (Hbuffer);
Osmemfree (HBuffer);
}
NifClosecollection (hcollection);
Osmemfree (HTABLE);
M_BgetunRead = True;
Return iViewunread;
}
//// closenotes: Close Notes database
Void cnotes :: closenotes ()
{
IF (m_bopened)
NSFDBClose (HDB);
m_bopened = false;
M_BgetunRead = false;
} Experience:
1. When you get an unread document list with the NSFDBGetunReadNotable function, it is found that when you read the local database, the unread document list is correct, while when reading the database (even if you are a copy of the book locally) The list of unread documents of the replica is also the same. number. 2. The number of unread documents obtained above is that all unread documents of the entire database, which should be compared to the view document to really get an unread document for a view or folder.
3, Notes is required to have 0x13 characters before processing Chinese. Therefore, in processing Chinese databases, we must also process Chinese name issues themselves.
4. To further get the field content of the document, you can use the following function segments to be added to the above functions.
BOOL FFIRST = True;
INT j = 0;
Notehandle Notehandle;
While (Idscan (Htable, Ffirst, & Noteid)
{
Ffirst = false;
For (i = 0; i
IF (Noteid == Idlist [i]) {
IF (nsfnoteopen (HDB, Noteid, 0,? Ehandle) == noerror) {
NSFITEMGETTEXT (NoteHandle, Szitemname, Buffer [J], Max_Path);
}
J ;
Break;
}
}
5. This article is the main function of this feature, you can write it into a DLL program, then you can use it in your Notes Script script. You can also use it to write into a separate application, you can run it outside Notes.
This program is debugged under Windows2000 Server, Visual C 6.0. If there is any problem in this article, please contact the author.
references:
Lotus C API 5.0.7 User Guide
Lotus C API 5.0.7 Reference