Novell Home

Creating a Unique CN from the IDM UserApp

Novell Cool Solutions: Tip
By Rob Schneider

Digg This - Slashdot This

Posted: 5 Sep 2007


This is a variation on the theme found in Use Case 8 of the following AppNote written by Rudy Duym:

Use Case 8 in the AppNote did not meet my needs in two respects:

1. A different naming convention was required. The convention was to use up to the first 5 letters of surname + first initial of Given Name, and if duplicates are found, begin appending a counter. I needed to increment a counter ONLY if a duplicate CN already existed.

2. I needed to compare against all CNs in a tree, rather than seek a specific DN for existence. The interesting twist between the two scenarios is that the returned result of a global query is an array, and so the test on the query results had to do more than the example in Use Case 8.


Here's the code, most written by Rudy Duym, with my comments and modifications added for the query instead of the "IDVault.get" found in Use Case 8.

This code is placed in an onLoad event, on my CN field on the request form.

Sample Code

//The CN Field on the form is not something visible for user input;


//The following Computes CN;
           window.computeCN = function (invocation)
                    try {
                        var errors = form.validate();
                        if (errors) {
// Unique CN Generation;
                        var fn = form.getValue('GivenName');
                        var ln = form.getValue('Surname');
                        var cn;
                        var prefix=(ln.substring(0, ln.length > 5 ? 5 : ln.length) + fn.substring(0, 1)).toLowerCase();
                        for (var i = 0; i <99; i++) {
// First iteration cn does not have a number appended.  Subsequent loops get incrementing counter;
                            cn = prefix + (i == 0 ? "" : i);
                            form.setValues('cn', cn);
                            try {
// A query object called "uniqueCN is passed a filtering parameter... the computed cn value.;
                                var v = IDVault.globalQuery(null, "uniqueCN", {"cN":cn})
                            } catch (e) {
// The global query returns an array: V[0] is the dn of an object with a matching cn and v[1] is the cn;
                            if (v[1] == cn) {
                                form.showMsg("cn " + cn + " already exists at " + v[0]);
                            } else {
                                alert("This User's Unique Login ID= " + cn);
                    } catch (e) {
                form.interceptAction("SubmitAction", "around", window.computeCN);

Below is the CN Global Query that had to be created. (Of course, the User entity had to have the CN attribute searchable.)

Figure 1 - CN Global Query

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© 2014 Novell