Wednesday, 28 March 2007

A Minor annoyance

If there's one thing that does annoy me about Notes as a Developer (Yes I know this is the Lotus Notes Rocks blog, but it's not perfect, just accept that) a it's that some of the Lotusscript commands don't work as I feel they should.

The command that has caught me out today, not for the first time as well, is the view.GetDocumentByKey command. This seems like a fairly simple command and it is, it is very useful and I use it all over the place, however it does have what I think is a logical flaw. If you have a view containing a number of documents with the first column containing say a Town Name and this column is sorted.
Lets say we have a number of Documents covering various towns,
  • High Wycombe,
  • Reading,
  • Marlow &
  • Marlow Bottom.
I then run an agent to get me the Marlow entry, using the command view.GetDocumentByKey("Marlow") and lo and behold we now have the Marlow document. However down the line, the Marlow document is removed from the system, at from then on when the agent runs you would expect it to return some kind of error that the Marlow document no longer exists, however given the way the command has been built, by default it will accept a partial match and therefore returns the Marlow Bottom document.

Now there is a boolean parameter that sits on the end that will force it to perform an exact match, however by default a partial match is enough. For the novice developer this is very dangerous and I can speak from experience that it can cause major problems if you don't spot the need for the exact match.

An agent I wrote that went through a database each time a new document was created, checked against a particular number on the document to see if the doc number already existed with the same revision that the new document had and if there was such a document it was removed, as this new document was obviously supposed to overwrite it. For many weeks we tried to understand why sometimes documents with a zero on the end of the document number, went missing. Of course we eventually spotted the extra parameter and realised that if you created a Document 12345 Revision 1, if it didn't already exist in the system and Document 123450 Revision 1 did, that 123450 document would get removed.

That was the first time it caught me out and todays was the second hopefully I will remember to add the parameter every time from here on and there will never be a third!! So there you go, the first gotacha that you need to look out for if you are just moving into Lotus Notes Development.

1 comment:

Michael Duffy said...

i might have some developement work to put yer way soon if yer fecking interested, our developers just quit. the big fecking bastard