dominoGuru.com

Your Development & Design Resource

XPage Primer: Using the ContactPhoto Image via SSJS

dominoGuru.com XPages Primer

I wanted my upcoming XPage Maps proof of concept (IBM Lotus Notes Domino XPages + Personal Address Book + Google Maps Mashup) to be a little more user friendly than I had originally intended. See, my original goal was to simply query address data from the Lotus Notes Client Personal Address Book and use that address data for runtime queries to Latitude and Longitude info... and then show those as locations on the map via pin overlays.

A decent demo, but it really doesn't do much in the way of using the data.

So I thought that I would not only generate the balloon/popup overlays triggered via an onclick on the given pin, but also use -- if available -- the ContactPhoto for the individual pin overlay.

Now, for those of you not familiar with the concepts I'm using here -- which rely as much on traditional IBM Lotus Notes Domino Web Application Development as much as XPages and SSJS -- here is the short, short version of the principles used here.

  1. db.nsf/0/UNID is a perfectly valid and operational URL schema. When performing READ operations against a NotesDocument via the Universal ID (UNID), the View designation really doesn't matter. I'm using 0, but you could just as well use db.nsf/IBM Lotus Notes is an excellent enterprise application platform/UNID... the name ultimately doesn't matter.*
  2. db.nsf/0/UNID/$File/[Attachment Name] is a perfectly valid and operational URL schema for reading a file attachment in a NotesDocument.
  3. The IBM Lotus Notes Personal Address Book Contact|Person Form Design Element's Photo Rich Text Lite Field forces the file attachment name to ContactPhoto.

* -- Views can still be used to set Form Formulas, but do not use Form Formulas for application security (at all, but) especially when using UNIDs.

So, via SSJS, I'm simply going to check a given Contact NotesDocument (contactRecord) for the existence of any $File NotesItems (a leap, I know... but it's a proof of concept...).

If there is a $File, I will set the logo variable to the ContactPhoto, otherwise to a default pin PNG.

if (contactRecord.getDocument().hasItem("$File")) {
    var _docUNID = contactRecord.getDocument().toString();
    var logo = "/names.nsf/0/" + _docUNID + "/$file/ContactPhoto";
   
} else {
    var logo = "/default.png";
}

The result is a per-NotesDocument logo URL that I can use for my Google Maps overlays!

XPage Maps Example: Chris Toohey - 
Pennsylvania, US

I plan to release XPage Maps early this week -- if not sometime later today -- but I thought that this simple example deserved it's own post. Understanding that there is an absolute need for XPage developers to understand core functionality of the platform is a given, but I don't think it's often stated that not having knowledge of the quirks of the platform can lead to misconceptions of the capabilities of the platform.

One final note: Some XPage developers may assume that I'm using a Data Table or Repeat Control with a defined Data Source to display this data... but I'm not. I'm using an SSJS Library and a Script Block:

<xp:scriptBlock value="initialize(#{javascript:return getContacts();});" />

... but more on that when I release XPage Maps.


About the author: Chris Toohey

Thought Leadership, Web & Mobile Application Development, Solutions Integration, Technical Writing & Mentoring

A published developer and webmaster of dominoGuru.com, Chris Toohey specializes in platform application development, solutions integration, and evangelism of platform capabilities and best practices.



More from dominoGuru.com


dominoGuru.com is powered by IBM Notes Domino XPages & hosted by Prominic.NET

Contact Us

Use our Contact / Feedback form or one of these email addresses:

Creative Commons License

Except where otherwise noted, dominoGuru.com by Chris Toohey is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.