Share your thoughts and find that its getting better every day. This work of mine helps me realize that.
Tuesday, September 10, 2013
Custom sort using @Sort in lotus notes
I happened to cross through a scenario where I had to perform a custom sort in such a way that a list of words appear in a drop down in such a way that "Red" if present always appears first followed by "White" and "Blue" if they are present and the rest of the list must be alphabetically sorted.
I found a close way to do that but not the best solution though. It took me quite a while to understand the way the parameters "$A" and "$B" were used in the @Sort function.
I use a list named a s"myList" as an input parameter. The list elements present inside my list is as follows
Blue : Custom : XCustom : Red : DCustom : White
Take a look at the following code.
@Sort(myList; [CustomSort]; @Do(
@If(
@UpperCase($A)="RED";-1;
@UpperCase($A)="WHITE" & @UpperCase($B)="RED";1;
@UpperCase($A)="WHITE" & @UpperCase($B)!="RED";-1;
@UpperCase($A)="BLUE" & (@UpperCase($B)="WHITE" | @UpperCase($B)="RED") ;1;
@UpperCase($A)="BLUE" & !(@UpperCase($B)="WHITE" | @UpperCase($B)="RED") ;-1;
@UpperCase($A)>@UpperCase($B)
)
) )
The out put that I have obtained is as follows
Red : White : Blue : Custom : DCustom : XCustom
When I change the last line of code to @UpperCase($A)<@UpperCase($B) my out put becomes
Red : White : Blue : XCustom : DCustom : Custom
It returns two types of values 1 and -1. The confusion was, It is supposed to return an integer equivalent for @true and @false which are to my understanding 1 and 0 respectively.
I dont know how was one able to think about the scenario of using -1 as a return type which was not documented in Designer help. It works great.
As per my understanding if you return
1 - it means $A will be put behind $B in the list after the comparison occurred
0 or -1 - it means $A will be put in front of $B in the list after the comparison occurred.
-2 ( and probably all other negative number) is treated like 0 as well O.o
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment