AutoPopulateGroup (If You Do Not Run Domino 8.5)

A 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, 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
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 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 ="", searchCriteria, ctls);
		PopulateGroup (answer, doc);

	    		} catch(NamingException e) {

	    } catch (Exception e) {
} // 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);
            		result = (String)sr.getName();
           	} // end of while

			doc.replaceItemValue(fldTmpMembers, v);;
	catch (NamingException e) {
    		} catch (Exception e) {
	} // 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.

Download sample database

Tweak The Auto-Populated Groups Feature In Domino 8.5

Yesterday I wrote about the new Auto-Populated Groups in Domino 8.5 . Today I want to show, how you can tweak this feature by just adding a new subform to names.nsf on the server and not using any additional code or modifying existing code to make the feature work.

As we learned yesterday, Domino uses LDAP and a LDAP Query to populate the members field in an auto-populated group.

In 8.5 Beta 1 you can only select the option “HomeServer” in the “Auto Populate Method” field which results in a fixed string in the “SelectionCriteria” field . This field is computed and you cannot modify its value.

We could easily make this field editable. But this means to modify the standard coding which is not always a good idea.

But you can achieve the aim in another way. Follow these steps

  • Create a new subform
  • Create a new field on the subform ( SelectionCriteria, Text, Editable )
  • Give it the name Custom and an alias starting with $AutoPopulate followed by a number of your choice ( i.e. 9999)
  • Save the subform

When you now create a new group, the “Auto Populate Method” field contains a new option … Custom. Magic, isn’t it ?

In fact it is not magic at all. When you open a group form in edit mode, the “Sub GenerateSubFormsList” in subform $GroupInheritableSchema reads all design elements¬† and fills the “SubformsList” field with the names of all subforms starting with $AutoPopulate as an alias.

Then the following formula shows the subform according to the choice you make as an auto populate method

@If(AutoPopulate="" | AutoPopulate="0";"";"$AutoPopulate" + AutoPopulate)

That’s it, folks!

By the way, this is a great example of how to write code that allows enhancements without changing the code.

Auto-Populated Groups in Domino 8.5

Domino 8.5 comes with a new feature to use predefined criteria to automatically determine and update group membership.

Complete these steps to set up an auto-populated home server group.

  • Set up a Home Server auto-populated group in a Group document.
  • Specify the update interval for auto-populated groups in the Domino Directory Profile document.

and ( this is not in the administrator help for 8.5 )

  • You must have LDAP enabled on the server.

Why LDAP ? Take a look at the “SelectionCriteria” field in the recently created group document.