views:

487

answers:

5

Hi everyone,

I've been tasked with learning Lotus Domino Designer - not sure what I did in a previous life, but it must have been pretty bad... - and was wondering how to do a lookup on a database to get some values for selections. As this information could potentially be used in a lot of the applications, I'd prefer it only to be in the one place.

I gather I can use @DBColumn, but what happens if an entry in that lookup changes? If the unique value of the lookup is the text, then the relationship would be broken, wouldn't it? Is there any way of mimicing the idea of relational lookups?

I'm assuming I'm looking at Lotus development from the wrong angle, as this seems to be a real limitation of look ups.

I haven't found any decent learning material on the interwebs, so would appreciate any help.

Ta

A: 

It depends on where your using the data. The @DBLookup or @DBColumn will work in Lotus Notes fields if the fields are set to be computed for display. That way they always get the most up to date information when you open the form etc.

If you make it so the data is saved on to the document then you will have to write some update code when you need to refresh the values.

The Lotus Notes help files for designer are pretty good, have a look at that.

SM

smithchelluk
Thanks. But say, if one of the values had been entered incorrectly, the data is used in a different database, and the value corrected, the data would not be synchronised. I'm thinking more of using an id field like in SQLServer/MYSQL etc, so the value itself is irrelevant.
Paul
It would be though. Everytime the document in the 2nd DB is opened the Computed for display field would do the lookup to the 1st database and render the correct value.As I say you never save the value to the 2nd database. It's a dynamic lookup.
smithchelluk
+1  A: 

If you need relational properties, look for non-Notes solutions. It is possible to get some relational behavior using document UNIDs and update agents, but it will be harder than with a proper relational backend.

Your specific problem with referencing to a piece of text that might change can to some extent be resolved by using aliases in the choice fields. If a dialog list contains values on the form...

Foo|id1
Bar|id2

...the form will display Foo but the back-end document will store the value id1 - (and this is what you will be able to show in standard views - although xpages could solve that). Using the @DocumentUniqueID for alias can be a good idea under some circumstances.

Anders Lindahl
+2  A: 

You would want to store a unique ID along with the textual value in the source database (not unlike what you would do in an RDBMS). Then, only store that ID in any referencing documents, and use a computed-for-display field to lookup the display value. (There is a performance consideration here - and you could "de-normalize" the data and store the ID and text value in the referencing documents, and do some asynchronous work to keep the values in sync - eg: using a scheduled agent that runs every night or every week).

If DB1 has the key values and DB2 has the documents which will reference these values, then in the form in DB2, you would still do a @DbColumn to lookup your value list. In the lookup view in DB1, concat the text value and ID with a pipe separator (textField + "|" + ID) in the first column. That will tell Notes to store only the ID value (what follows the pipe is the "alias" and is what will be stored).

Note: I would avoid using @DocumentUniqueID as the unique ID for these values, as the Document Unique ID will change if the documents are copied and pasted, or the entire database is copied, etc. You can use the @unique formula function in a computed-when-composed field to generate something close to a unique ID (almost like an identity column in sql).

Ed Schembor
+1 Good point about @documentuniqueid, I didn't know that function of @unique.
Anders Lindahl
A: 

You could use a key or alias to store the relationship to your lookup value so if the value itself changes, the connection remains because the alias is intact. For example, if your lookup values were being stored as a collection of documents, I'd have the @DBColumn retrieve Document UNID|lookup value pairs. When in display mode, you could then retrive the value using @GetDocField. If the lookup values are in a different database, then you'd have to retrieve them for display using @DBLookup and construct a view that is keyed off of the UNID or whatever key you decide to use.The only drawback to this technique is that you wouldn't be able to display the field value in views as the actual value isn't stored in the document, just a reference to it. Using XPages, though, you COULD map the relationship into a dynamic datatable just like you would in a truly relational system.

It's tricky, but using LEI, you could also use Notes to front-end a relational backend system, also giving you the dynamic relationship you desire in your lookups.

Hope this helps!

Jake
A: 

The content of the lookup can change freely. A problem only arises (as it would on any other platform in the same circumstances) if the lookup key changes. You need to use a key that won't change. Human-readable text is an advantage, but if you want to be able to change your key description from, say, "Divisions" to "Business Units" and still have lookups work, you need to use an alias of some kind, which will presumably be mapped to your text description and only used internally. @Unique is pretty good for this, and gives a shortish key, if that is important to you. @DocumentUniqueID is most reliable, but as Ed pointed out, will change (must change - it's a new document) if you copy/paste or make a non-replica copy. This is easy to get around, though. Create a Computed-when-composed field (called, say, "LookupRef") on the form you are using for your reference document with the formula "@DocumentUniqueID". That will capture the ID at the time of creation, and it will not change on copy/paste etc. Use that as your key.

Andrew Brew