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.

Almost over

The Christmas break is coming to an end today (for me at least) as I have to go back to work tomorrow. It’s been a hugely relaxing few days, very quiet, but that was exactly what was called for after a fairly hectic few months. The main thing learned from this year is that I need more than 10 days holiday. I honestly don’t know how our American colleagues can work productively with only 2 weeks vacation.

The emphasis of things (in the Lotus world at least) will switch to Lotusphere for the next few weeks but until the new year I imagine it will stay pretty quiet here unless I am very bored at work. Although that is quite likely as I think there are only a couple of us in the office until next week.

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

Interesting if intimidating experience

On the short drive from the station back home this evening I got stopped by the police for a random breath test. Because I was doing 3mph over the limit apparently that was enough to stop me, although I was told immediately that they weren’t going to do anything about it. What they really wanted was to do a breath test as part of the pre-Christmas crack down on drink driving.

It wasn’t a problem at all, not having had a drink since yesterday so I looked on the whole thing as an interesting experience. The little breath testing machine is very impressive, given the size of the tubes it takes only a tiny sample of air and then analyses it within ten seconds. I can imagine that if you had had a drink the experience would be extremely sobering (although maybe not quickly enough!) and enough to put you off drink driving on it’s own.

All in all something which I am glad that the police do.

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 ) )

PintWare button added

I have decided to start putting up a few of the more useful tips and tricks which I have picked up over the years. The real reason for this is that I managed to corrupt my local database which stores them all so didn’t have a little bit of code I needed to hand recently. However, you are more than welcome to use them if they are of any use to you. You’ll see a couple have already been posted and there will be a lot more over the next month or so.

I realise that there are a lot of sites out there which give away tips and tricks, it’s very cool, however I have also seen a few sites which ask for a little recompense, it’s really an extension of the Shareware philosophy into what a few people are calling PintWare. You’ll notice there’s a new button at the top left of this page, when you click it you get taken through to PayPal. No obligations but if you find that something has been useful, please consider donating a little to me, it will help keep the site going and make you feel all warm and fuzzy!