Subject: RE: Logic question
This is the version that works at the moment, well for the most part anyhow.
Have gone back to formula language as lotusscript and javascript were getting too ugly and confusing and more importantly not working.
At the end of the day, the code isn’t that important. My question is more why i have to combine fields in a certain order to get them to work when to my twisted sense of logic, I should be able to put them on either side of an AND or an OR and get the same answers. x or y should be the same as y or x
simplied version of the form (minus the javscript and css):
fields:
SearchType - radio button - Delegation / Authorisation|1, Exemption|2. Used to set the formtype below
SearchLookFor - radiobutton - Any|2, All|1
Act - listbox - “None”:@DbColumn(“”:“NoCache”;“”;“AllActs”;1)
Regulations - listbox - “None”:@DbColumn(“”:“NoCache”;“”;“AllRegs”;1)
Position - listbox - “None”:@DbColumn(“”:“NoCache”;“”;“Positions”;2)
Word1, Word2, Word3, Word4, Word5, Word6, Word7, Word8 - 8 text field
CreateModify - listbox - effective date|[GazettalDate]. additional options when admin users logged in.
BeforeAfter - listbox - on|=, from|>=, before|<=
QueryDate - text - javascript date picker and validation
DateChoice - listbox - effective date|[GazettalDate]. additional options when admin users logged in.
AfterDate - text - javascript date picker and validation
BeforeDate - text - javascript date picker and validation
FormType - listbox - All | FILALL, Delegations | DelAll, Authorisations | AuthAll
SearchMaxResults - listbox - All | 0, 10, 50, 100
Search code in full.
REM {if nothing is selected, display 2nd search form with error message advising user need to select something to search for. 1st option in each keyword field is None and there is no default set};
@If((Act=“None” | Act=“” )& (Regulations =“None” | Regulations=“”) & (Position =“None” | Position = “”) & Word1=“” & Word2=“” & Word3=“” & Word4=“” & Word5=“” & Word6=“” & Word7=“” & Word8=“” & QueryDate=“” & AfterDate=“” & BeforeDate=“”; @Return(“[/”+@WebDbName+“/WSAdvanced2]”);@Success);
REM {set up AND or OR for the rest of the search. Default is OR};
x:=@If(SearchLookFor=“1”;" AND “;SearchLookFor=“2”;” OR “;”");
REM {if text entered in word fields, combine them. trying to accomodate the fact that people might enter test in box other order than top-left to bottom–right};
words8:=@If(Word1!=“”;Word1;“”);
words7:=@If(words8!=“” & Word2!=“”; words8 + x + Word2; words8=“” & Word2!=“”; Word2; Word2=“” & words8!=“”; words8;“”);
words6:=@If(words7!=“” & Word3!=“”; words7 + x + Word3; words7=“” & Word3!=“”; Word3; Word3=“” & words7!=“”; words7;“”);
words5:=@If(words6!=“” & Word4!=“”; words6 + x + Word4; words6=“” & Word4!=“”; Word4; Word4=“” & words6!=“”; words6;“”);
words4:=@If(words5!=“” & Word5!=“”; words5 + x + Word5; words5=“” & Word5!=“”; Word5; Word5=“” & words5!=“”; words5;“”);
words3:=@If(words4!=“” & Word6!=“”; words4 + x + Word6; words4=“” & Word6!=“”; Word6; Word6=“” & words4!=“”; words4;“”);
words2:=@If(words3!=“” & Word7!=“”; words3 + x + Word7; words3=“” & Word7!=“”; Word7; Word7=“” & words3!=“” ; words3;“”);
words:=@If(words2!=“” & Word8!=“”; words2 + x + Word8; words2=“” & Word8!=“”; Word8; Word8=“” & words2!=“”; words2;“”);
REM {set up searching for on, from and before a single date. Aliases used in BeforeAfter field: on|=, from|>=, before|<= };
date:=@If(QueryDate!=“” & CreateModify!=“” & BeforeAfter!=“”; CreateModify + BeforeAfter + QueryDate;“”);
REM {set up searching for date range. set up for after (>=) and before (<=). if dates entered round wrong way, search won’t present correct search};
daterange:=@If(DateChoice!=“” & AfterDate!=“” & BeforeDate!=“”; DateChoice + “>=”+ AfterDate +" AND " + DateChoice + “<=” + BeforeDate ;“”);
REM {combine search on Act and Position fields with operator. Tried with Regulation originally but that wasn’t working so went with position instead. used to enclose field names. “” used around search term so phrase is searched for };
searchfor1:=@If((Act!=“” & Act !=“None”) & (Position!=“” & Position!=“None”);“[Act]="” + Act +“" " + x + " [Position]="”+Position+“"”; ((Act=“” | Act =“None”) & (Position!=“” & Position!=“None”));“[Position]="”+Position+“"”; ((Position=“” | Position =“None”) & (Act!=“” & Act !=“None”)) ;“[Act]="”+ Act +“"”; “”);
REM {combine results of Act and Position combination with search on Regulations. Note field name on data entry forms is Regulation. This is different to Regulations on the search form. Tried with Regulation originally but that wasn’t working so went with regulations instead. };
searchfor2:=@If((searchfor1!=“” & searchfor1!=“None” ) & (Regulations!=“” & Regulations!=“None” ); “[Regulation]="”+Regulations+“"” + x + searchfor1; ((searchfor1=“” | searchfor1=“None” ) & (Regulations!=“” & Regulations!=“None” )); “[Regulation]="”+Regulations + “"”; ((Regulations=“” | Regulations=“None”)&(searchfor1!=“” & searchfor1!=“None” )); searchfor1;“”);
REM {combine results of Act, Position, Regulation combination with values from word fields};
searchfor3:=@If((searchfor2!=“” & searchfor2!=“None”) & words!=“”; searchfor2 + " " + x +" " + words; ((searchfor2=“” | searchfor2=“None”) & words!=“” ); words; (words=“” & (searchfor2!=“” & searchfor2!=“None”) ); searchfor2;“”);
REM {add the single date comparison in};
searchfor4:=@If(searchfor3!=“” & date!=“”;searchfor3 + x + date; (searchfor3=“” & date!=“” ); date; (date=“” & searchfor3!=“”) ; searchfor3;“”);
REM {add the date range comparison in to the mix};
searchfor:=@If(searchfor4!=“” & daterange!=“”; searchfor4 + x + daterange; (searchfor4=“” & daterange!=“”) ; daterange; (daterange=“” & searchfor4!=“” ); searchfor4;“”);
REM {set up maximum number of results to return. If All is chosen, there is only the notes limit of 5000};
options:=@If( SearchMaxResults=“0”; “”; “&SearchMax=” + SearchMaxResults );
REM {run search and present results};
“[/”+@WebDbName + “/”+FormType+“?SearchView&Query=” + searchfor + “&SearchOrder=4” +Options + “]”