<< 19 December 2007 | Home | 21 December 2007 >>

I'm on holiday... :-)

I'm now on holiday and I wont be back in the office until 3 January 2008. How nice is that! I really feel I need a couple of days off. The last 3 months after my switch to IntraVision has been eventful and even more full with work. A couple of days of will do me good I think.

When I'm back in the office I'm only there for 8 days before leaving for Orlando.

Happy holidays to you all... :-)

Lotus Connections Profiles - using JavaScript to translate data for TDI

I have been working with Lotus Connections lately and wanted to share a tidbit of code for the profiles database population step.

During the population of the profiles database from Domino LDAP using TDI (Tivoli Directory Integrator) I needed to translate country names to the matching ISO country code as this is what is used in Lotus Connections. To do this you can write a Javascript function in profiles_functions.js and map it in map_dbrepos_from_source.properties. The documentation on this is very lacking but through some trial-and-error and with a little help from Mac i cracked it.

Below is the function I wrote (with only a few countries) to show how to write the function which isn't apparent at all. The error output from TDI simply indicates a "parse error" if your Javascript is wrong for whatever reason.

I hope this can save someone some time...

The tricks:

  • Define "fieldname" as a parameter to the function. I don't use it but at least one parameter is required.
  • Use the available "work" variable to get data from the backend LDAP directory using the getAttribute method.
  • Use the available "system" variable to create a new attribute to replace the one we find.
  • Return the constructed attribute to have it show up in the profiles database.
  • The Javascript is actually accessing Java objects in the backend. Keep this in mind when comparing Strings - remember to use String.equals!

map_dbrepos_from_source.properties

PROF_ISO_COUNTRY_CODE={func_xlate_country}
profiles_functions.js
function func_xlate_country(fieldname) {
  // init arrays for translation
  var iso_codes = new Array("DK", "IE", "DE");
  var iso_ctry = new Array("Denmark", "Ireland", "Germany");
  
  // get attribute
  var ctry = work.getAttribute("c");
  if (null != c) {
    // get value from attribute
    var val = ctry.getValue(0);
    
    // loop array
    for (var i=0; i<iso_ctry.length; i++) {
      // match country name from attribute against current 
      // array position
      if (val.equalsIgnoreCase(iso_ctry[i])) {
        // found one - create new attribute to hold 
        // our translated value and set it
        ctry = system.newAttribute("c");
        ctry.addValue(iso_codes[i].toLowerCase());
      }
    }
  }
  
  // return attribute to TDI
  return ctry;
}