logo

Another tip when using "lookups"

Have you ever done more than one @DBLookup to a single document because you want to get more than one field's value? Naughty! Maybe you've tried the approach of imploding all the values you need in to one column and working on that list? What about creating a multi-value field on the document that holds each value you are interested in and then working on subsets of that? An example might be where you want to return the Title, Author and Date of an article. I'm sure we've all done something like this at least once.

Well, I've recently changed the way I do things like this. Here's how. As of Domino 6 lists can be subscripted. What? Well, you can get the second value of a multivalue field called "summary" like so:

author:=summary2 ];

Instead of combining all the fields in a column I do it in a multi-value computed field on the document, that use New Lines as separators. In this case the formula would be

Title : Author : Date

Remember our demo database where documents simply listed the title of each "related article". Well, here's an updated formula that also displays the author and date.

html:="";
@For(n := 1; n <= @Elements(RelatedArticles); n := n + 1;
summary:=@GetDocField( RelatedArticlesn ]; "Summary");
html := html + @If( @IsError( summary ); "";
"<a href=\"/" + @WebDBName + "/0/" + RelatedArticlesn ]+ "\">" + summary1 ] + "</a> by " + summary2 ] + " on " + summary3 ] + "<br />" )
);
html

There are others ways of doing the same thing. You could simply compile the HTML link in a column and return the column value in a DBLookup. For now though I am assuming we want to do away with the view and use @GetDocField. Here also, you could have a computed field that compiled the HTML required for each link and simply return the value of the field. The above formula is a little more flexible though. Imagine you want to show author and date in one place and only date in another. You can easily tailor this code without having to update any documents. As ever, this is open to discussion...

Comments

  1. Wow. I'm a little surprised there's yet to be any discussion on this.

    This is very useful and powerful stuff. I've got formula language now doing what I would have had to write a nasty agent to do in the past... and what's nice, the formula language is in a computed text field on a web form. Now I don't even have to worry about getting the output from the agent to the right spot on the form. :-)

    Only down side is that you can't put it on the left of an assignement operator... makes things more complicated than they need to be to build a list with an @for function.

    Still makes me happy. :-)

    • avatar
    • Jerry Carter
    • Fri 14 May 2004 23:07

    I should note, you can use @Transform to bang up an entire list if you want to process a whole list into a new list. That's pretty handy too, and doesn't need fiddling with [].

    • avatar
    • raj
    • Thu 20 May 2004 10:50

    this is a good article , helped us a lot in undersgtanding the application concepts in the apllicate

    • avatar
    • zomek
    • Mon 31 May 2004 02:58 AM

    Pretty smart, but I would consider this technique as an example rather than as a real world method ;) From my experience, the computed "summary" fields got one BIG disadvantage - when any changes are made in document programatically (agents, actions etc.), not with form you have to (remember to) actualize the value of summary field. And it could be messy (error prone and resource consuming)! :(

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Tue 11 May 2004

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content