AutoPopulateGroup (If You Do Not Run Domino 8.5)
June 22, 2008 – 10:18 amA few days ago, I wrote about a new feature of Domino 8.5 to automatically populate groups via a LDAP selectioncriteria. This is a great feature and I have successfully tested it on my sandbox server.
Since we run Domino 8.0.1 on our productive servers, we cannot use this very useful feature. …
But, with a few lines of JAVA and Lotusscript code, you can build your own solution to auto populate groups. Here is what I came out with.
I’ve created a subform with two fields and a button.

- HiddenMembers, Text, hidden
- SelectionCriteria, Text, editable
The “Populate Group” button contains the following code
'/* Declaration Const fldMEMBERS = "Members" Const fldHIDDEN = "HiddenMembers" Const agntDOLDAP = "AutoPopulateGroup" Sub Click(Source As Button) Dim s As New NotesSession Dim ws As New NotesUIWorkspace Dim db As NotesDatabase Dim agent As NotesAgent Dim doc As NotesDocument Dim uidoc As NotesUIDocument Dim searchResultItem As NotesItem Dim paramid As String Set db = s.CurrentDatabase Set uidoc = ws.CurrentDocument Set doc = uidoc.Document Set agent = db.GetAgent(agntDOLDAP) Call doc.save(True, False) paramid = doc.NoteID Call agent.RunOnServer(paramid) Delete doc Set doc = db.GetDocumentByID(paramid) Set searchResultItem = doc.getFirstItem(fldHIDDEN) Call uidoc.FieldSettext( fldMEMBERS, "") Forall values In searchResultItem.Values Call uidoc.FieldAppendText(fldMEMBERS, values) Call uidoc.FieldAppendText(fldMEMBERS, Chr(10)) End Forall Call uidoc.Refresh doc.Remove(True) End Sub
Like in Domino 8.5 you’ll have to run LDAP on your server. To access LDAP and do a search according to the SelectionCriteria, you need an agent with the following piece of Java code.
import lotus.domino.*; import javax.naming.*; import javax.naming.directory.*; import java.util.Hashtable; import java.util.Vector; public class LDAPSearchWithFilter extends AgentBase { private static String fldTmpMembers = "HiddenMembers"; public void NotesMain() { try { Database _db; Document _doc; Session session = getSession(); AgentContext agentContext = session.getAgentContext(); _db = agentContext.getCurrentDatabase(); Agent ag1 = agentContext.getCurrentAgent(); String paramid = ag1.getParameterDocID(); Document doc = _db.getDocumentByID(paramid); String searchCriteria = doc.getItemValueString("SelectionCriteria"); String ldapCF = "com.sun.jndi.ldap.LdapCtxFactory"; String ldapURL = "ldap://localhost:389/"; String ldapBaseDN = ""; String ldapUserID = ""; String ldapPassword = ""; Hashtable env = new Hashtable(4); env.put(Context.INITIAL_CONTEXT_FACTORY, ldapCF); env.put(Context.PROVIDER_URL, ldapURL + ldapBaseDN); env.put(Context.SECURITY_PRINCIPAL, ldapUserID); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); try { DirContext ctx = new InitialDirContext(env); SearchControls ctls = new SearchControls(); NamingEnumeration answer = ctx.search("", searchCriteria, ctls); PopulateGroup (answer, doc); ctx.close(); } catch(NamingException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } // end of Main public static void PopulateGroup(NamingEnumeration col, Document doc) { try { Item item = doc.getFirstItem(fldTmpMembers); Vector v = new Vector(); String result; if (col.hasMore()) { while (col.hasMore()) { SearchResult sr = (SearchResult)col.next(); result = (String)sr.getName(); v.addElement(result.replace(',','/')); } // end of while doc.replaceItemValue(fldTmpMembers, v); doc.save(true); } } catch (NamingException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } // end of PopulateGroup } // end of class
Set the agent’s runtime security to “2″, to allow restricted operations. When you have all code in place, you can test the function by typing a selection criteria and clicking the button.

The members field in your form should now show all persons that have “serv01″ as their mailserver.





Sorry, comments for this entry are closed at this time.