wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

Sharing HideWhen Formulas


Yes - a Notes classic development post, since XPages knows a "rendered" property (labeled as "visible") but no "hideWhen". I was asked " How can I share HideWhen formulas?". The short answer is: " You can't". The long answer: " Once you separate the label from the logic it becomes possible". Let me elaborate:
Instead of adding business logic to your hidewhen formula in the formula window itself you just enter keywords that describe the condition, something like isManager or isConfidential (Important: that are FIELD names, so no quotes). I like using "is" as prefix since the keyword describes a state of the document and based on that state information is supposed to be shown or hidden. De facto you create your domain specific language here. Now you create one computed for display (CfD) numeric field with exactly that name, so you have fields named isManager or isConfidential. That fields need to have results that are either @True or @False. To get to that result you can use anything at your disposal including profile documents or <gasp>@DBLookup or @DBColumn</gasp>. You could allow simple AND or OR statements like isDraft | !isManagerHaving done that you can start thinking about reuse.
Pack all the fields into a subform and put it at the beginning end of your form. In computation sequence fields are calculated first before HideWhen is executed, so putting them last ensures that you have the right values in them and don't need 2 recomputations. Quite often you will not use all hide conditions in all forms, so you might perform lookups that are discarded without being used. To avoid that you can use the following strategy. Add a CfD field, type text - multivalue, before the subform. Name it " HideWhenUsedHere". In its formula (which would differ from form to form) you list the HideWhen types you want to use e.g "isManager":"isDraft" (Note: you have quotes here!). On a subform you would have a CfD field HideWhen_[Name of the subform]. When you add a subform you would adjust the HideWhenUsedHere formula to look like @Trim(@Unique("isManager":"isDraft":HideWhen_[Name of the subform])). Then add to the first line of each CfD field of your hidewhen-subform: @if(@IsNotMember(@ThisName;HideWhenUsedHere);@Return(@False);""); This way your eventual longer running lookup won't execute. The @isMember executes very fast. Of course you could construct it the other way around and have a field " DoNotUseTheseHideWhenHere", then the first line would look like this: @if(@IsMember(@ThisName;DoNotUseTheseHideWhenHere);@Return(@False);"");
It is not as elegant or powerful as a SSJS library in XPages, but once you wrap your head around it provides an easy resuable way for your "business visibility rules"
As usual: YMMV

Posted by on 07 March 2011 | Comments (1) | categories: Show-N-Tell Thursday

Comments

  1. posted by Palmi on Monday 07 March 2011 AD:
    Cool tip - thanks Emoticon biggrin.gif