Tips Tricks Samples

Quickly terminate a Domino Session

I am writing a session authentication tool which checks that your session is valid before trying to submit a document to the server as we have users who lose data quite frequently (a combination of short session times, SSL and their inability to learn!). Rather than extend the session timeouts we check to see if the session is valid by trying to open a page before submitting the form to the server. But to test this I need to expire my session quickly and often so enter a one line scriptlet:

javascript:document.cookie=”DomAuthSessId=; expires=Saturday, 01-Apr-1980 08:00:00 GMT ; path=/”;alert(“Session has been terminated.”);

You just save this as a favourite (or bookmark in Mozilla) and click it when you want to terminate your session.

Return elements from a list which contain a substring

One of the most annoying things I have found in list operations is how to only return elements that contain a value. Here is a solution:

To return entries in a list that contain “B”:

1: ABCX
DEFY
ABDC
DBXY

2: Replacesubstring of B with |||
A|||CX
DEFY
A|||DC
D|||XY

3: @Right of |
||CX

||DC
||XY

4: @LeftBack of 3 at |
|

|
|

5: 4 + Original List
|ABCX
DEFY
|ABDC
|DBXY

6: @Trim and @Right of 5
ABCX
ABDC
DBXY

initiallist:=”ABCX”:”DEFY”:”ABDC”:”DBXY”;
step1:=@ReplaceSubstring(initiallist; “B”; “|||”);
step2:=@Right(step1; “|”);
step3:=@LeftBack(step2; “|”);
step4:=step3 + initiallist;
step5:=@Right(step4; “|”);
step6:=@Trim(step5);

Convert Domino UniversalID into a GUID

Just about the simplest bit of LotusScript ever but one I use again and again. It converts a UNID (32 character hex string) into a GUID (for use in SQL Server in my case but pretty universal).

Function convertUNIDToGUID(strUNID) As String
  Dim strGuid As String
  If Instr(strUNID, “-“) = 0 Then
    strGuid = Mid$(strUNID, 1, 8) & “-“
    strGuid = strGuid & Mid$(strUNID, 9, 4) & “-“
    strGuid = strGuid & Mid$(strUNID, 13, 4) & “-“
    strGuid = strGuid & Mid$(strUNID, 17, 4) & “-“
    strGuid = strGuid & Mid$(strUNID, 21)
  End If
  convertXRDominoIDToGUID = strGuid
End Function

Get URL Parameter in Javascript

Just a useful little javascript function which will get a URL parameter and return it to you. For example if the current URL is “…?opendocument&id=testid” then calling getURLParam(“id”) will return “testid”.

function getURLParam(strParamName){
  var strReturn = “”;
  var strHref = window.location.href;
  if ( strHref.indexOf(“?”) > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf(“?”)).toLowerCase();
    var aQueryString = strQueryString.split(“&”);
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + “=”) > -1 ){
        var aParam = aQueryString[iParam].split(“=”);
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

Update (31st December 2006)
This posting has been around for a long time now and gets a lot of traffic. Although it will still work fine as long as you know its limitations, several people have pointed to this article as being a better solution. I totally agree, it’s well worth a look.

Update (27th February 2007)
A couple of bug fixes raised via email. Thanks to Oliver Bryant for those.

Field Editor Smart Icon

This is a really useful formula. Not one to let your users have access to but put it into an action button on an admin view and it will let you edit any field value on a document when used in a view icon or smart icon.

List := @DocFields; DataTypes := “Text” : “Text List” : “Date” : “Number”;
EditField := @Prompt( [OKCANCELLIST] ; “Select a field to alter” ; “Select the field you wish to alter:” ; “CustomerReply” ; List ) ;

Edit := @Prompt( [YESNO] ; “Confirm” ; “Are you sure you want to alter the current contents of field \”” + EditField + “\”.” );

RawValue := @If( Edit = 1 ; @Prompt( [OKCANCELEDIT] ;
“New Value” ; “Please enter the new desired value.” ; NULL ) ;
@Return(NULL) );

DataType := @Prompt( [OKCANCELLIST] ; “Data Type” ;
“Please Select the correct DataType” ; “Text” ; DataTypes );

@If( DataType = “Date” ; @SetField( EditField ;
@TextToTime( RawValue )) ; DataType = “Number” ;
@SetField( EditField ; @TextToNumber( RawValue )) ;
DataType = “Text List”; @SetField(EditField; @Explode(RawValue; “,;:”));
@SetField( EditField ; RawValue ) )

Extract Imported Class Files from an Agent

If you have lost the source code for a Java agent which has only class files stored in it use the following code to extract the class files:

Dim sess As New NotesSession
Dim db As New NotesDatabase(“myserver”, “mydatabase.nsf”)
Dim agent As NotesAgent
Dim doc As NotesDocument
Dim strUNID As String

Set agent = db.GetAgent(“MyAgent”)
strUNID = Left$(Right$(agent.NotesURL, 42), 32)
Set doc = db.GetDocumentByUNID(strUNID)
Call doc.Send(False, sess.EffectiveUserName)

You will receive a mail from yourself which contains each of the class files as an attachment. These can then be detached to your hard disk and a Java Decompiler used to extract the source code from them. I would recommend the DJ Java Decompiler (http://members.fortunecity.com/neshkov/dj.html).

Convert Double to BigDecimal

We have been doing a bit of Web Services integration between Domino and .Net. In our situation, the .Net application was interested in receiving numbers as BigDecimal objects. To this end I did a bit of investigation and found that this is the best way to convert from Double (my preferred format) in Java:

import java.math.BigDecimal;
/**
* A set of useful static methods to do with numbers
*/
public class Numbers
{
  /**
  * Converts a Double to BigDecimal in the most efficient and accurate manner
  * BigDecimal is the preferred format for .Net
  * @param number
  * @return
  */
  public static BigDecimal getBigDecimalFromDouble(Double number)
  {
    String strNumber = number.toString();
    BigDecimal bdReturn = new BigDecimal(strNumber);
    return bdReturn;
  }
}

Useful little tool

This is a great page if you are developing a website for the internet. It will tell you exactly what is returned to your browser when visiting a specific address. It’s also rather handy when you are hosting a site from home and want to check DNS is working properly etc.

Did you know…

Did you know… you can Ctrl+C to copy the text of a Windows popup error message box to the clipboard (via Joel)