Initializing Author and Reader Fields in XPages
Ok, sharing time once again....
I've learned from various sources that while you may create Author and/or Reader type fields in a simple form design element which will be used as a datasource for an XPage or Custom Control, when you go to save the datasource the "special" field flags of the Author/Reader field will not be set. You have set the flags specifically (but only once when the fields are initially set/saved.)
What I've created is a simple function in a script library which can be called in the postSaveDocument event of the datasource on the XPage or Custom Control.
Here's the function:
function setupAuthorReaderFields(doc, authorField, readerField)
var authitem:NotesItem = doc.getFirstItem(authorField);
// only do below work if the Authors field has not been setup as an "Authors" type field initially
var readitem:NotesItem = doc.getFirstItem(readerField);
It assumes you have one author type field and one reader type field, and also requires a handle to the datasource (doc).
As you can see, it checks to see if the author field already has the flag set, and if so, doesn't do anything else - so we're not setting the flags and saving the datasource each time, just the first time.
Here's the code I have in the postSaveDocument event on one of my Custom Controls, so you can see how I got the parameter values ready to pass in to the function:
var doc:NotesDocument = DeptDoc.getDocument();Obviously you may have a more complicated setup with multiple author or reader fields, or sometime just one or the other, this is just a simple example to start from.
var authorField = "docAuthors";
var readerField = "docReaders";
setupAuthorReaderFields(doc, authorField, readerField);
I'd welcome any feedback, corrections or enhancements you may want to chip in to make this an even better solution.