<< Lotusphere 2008: BALD | Home | I'm on holiday... :-) >>

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;
}


Avatar: Mac Guidera

Re: Lotus Connections Profiles - using JavaScript to translate data for TDI

Great work! And thanks for sharing.
Avatar: Mikkel Heisterberg

Re: Lotus Connections Profiles - using JavaScript to translate data for TDI

Thanks and thank you for the e-mail on loading pictures into Lotus Connections. I didn't get to that today but I will next time - it definitely helped my understanding of TDI. The installation is now running with complete profile info (except pictures) incl. reports-to etc. Very nice.

Boy - Websphere is a beast of its own! :-)

Add a comment Send a TrackBack