Manage Learn to apply best practices and optimize your operations.

New twist on view selection formulae

This tip describes a new twist on view selection formulae.

You Can View User Feedback To This Tip

Some view selection formulae can be very complicated: This and that, or that an this but only when it is the 7th friday in April etc.

It is possible to simplify this considerably (to read anyway) by using an @If statement and @True; @False.

Unlike in normal circumstances where @if take the first true statement and ends - in the view selection formulae it takes ALL statements and bases the selection on them ALL.

Here is a small example but it can be expanded as much as you like. I have tried to keep the example as simple as possible but with this method you can embed @Ifs and it should still be quite readable.


SELECT (Form="Form1") | (Form="Form2" & AddDate>@Adjust(@Today; 0; 0; -30; 0; 0; 0)) | (Form="Form3" & AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0)) | (Form="Form4" & AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0))

Can be rewritten as

SELECT
@If(
form = "Form1"; @True;
form = "Form2" & AddDate>@Adjust(@Today; 0; 0; -30; 0; 0; 0); @True;
form="Form3" & AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0);@True;
form="Form4" & AddDate>@Adjust(@Today; 0; 0; -60; 0; 0; 0); @True;
@False)

USER FEEDBACK TO THIS TIP

  • I know some that would choose to code that way, but they're typically the same types that would write a couple hundred lines of lotusScript rather than one or two lines of @'s. Why would anyone (on purpose) choose to 'clean up' view selection formulas by making them programmatically more complex? Just add a few hard returns after the |'s and the original formula's fine. SELECT (Form="Form1") | (Form="Form2" & AddDate>@Adjust(@Today; 0; 0; -30; 0; 0; 0)) | (Form="Form3" & AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0)) | (Form="Form4" & AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0)) Is easier to read, easier to write than: SELECT @If( form = "Form1"; @True; form = "Form2" & AddDate>@Adjust(@Today; 0; 0; -30; 0; 0; 0); @True; form="Form3" & AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0);@True; form="Form4" & AddDate>@Adjust(@Today; 0; 0; -60; 0; 0; 0); @True; @False) —Jeff Crayton
  • This seems to be saying that @If behaves differently in a view selection formula than it does elsewhere. I'm pretty sure this is not the case. The formula that uses @If is indeed more readable than the original formula given -- but the readability of the original formula could have been improved just as much by adding newlines in strategic places. If the real purpose is to avoid unnecessary @Adjusts -- a worth goal, for peak efficiency -- the formula could still be improved by being written as follows: SELECT @If( form = "Form2"; AddDate>@Adjust(@Today; 0; 0; -30; 0; 0; 0); form = "Form3"; AddDate>@Adjust(@Today; 0; 0; -7; 0; 0; 0); form = "Form4"; AddDate>@Adjust(@Today; 0; 0; -60; 0; 0; 0); form = "Form1") This assumes the four document types are approximately equally common. Note also the two formulas don't use the same @Adjust arguments; I assume this is a typo. —Andre Guirard
  • Concerning the tip "New twist on view selection formulae": While the tip is a valid one, the explanation is flawed. The submitter states "Unlike in normal circumstances where @if take the first true statement and ends - in the view selection formulae it takes ALL statements and bases the selection on them ALL." Actually, the @If still ends at the first true statement. What makes it seem like it doesn't end at that point is that the statement is evaluated separately for EACH DOCUMENT. If the original statement had been correct, the formula @If(form="myform";@true;form="myform" & myfield="";@false;@false) would not display documents with form="myform" & myfield="", because it would not have stopped at the first true statement. But in fact, this formula WILL display those documents. —Barbara Houchin
  • USER FEEDBACK TO THIS TIP

    • Cool responses from other users :) Is it worth responding to any of the comments? If you think so then add the following - if not then no worries :) To the first point - I purposefully coded it that way because the logic is easier to understand for a beginner who I was dealing with at the time. This tip isn't aimed at people who don't have any problems with Selection Formulae - it is their to make them easier to follow. To the second point - yep typo *blushes* To the third point - Thank you :) now that makes more sense! That is a very good explanation of how view indexes work :)—Mark Roden

Dig Deeper on Domino Resources - Part 6

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close