Search code examples
lotus-noteslotusscript

Lotusscript sort 3 Text-Lists. Text-List 2 & 3 will follow sorting of Text-List 1


In my document I have 3 Text-List fields. I can sort the first Text-List ascending just fine. But how do I make Text-List 2 & 3 follow the final sorting of Text-List 1? Something like the following:

Before sorting:

Text-List 1 (C, A, D, B), Text-List 2 (W, X, Y, Z), Text-List 3 (L, I, S, T)

After sorting (I'd want it to be like the following):

Text-List 1 (A, B, C, D), Text-List 2 (X, Z, W, Y), Text-List 3 (I, T, L, S)

Is there any way to achieve this? I tried putting each of the Text-List into array but it's too much problem for me to compare which element in Text-List 1 should came first while keeping track of the index in a temporary variable and using the index to re-sort Text-List 2 & 3 by transferring their element into their respective second temporary array.


Solution

  • Assuming you have

    • three fields in your document List1, List2 and List3
    • they have all the same amount of list elements
    • they won't be together larger then 64K

    then you can concatenate the lists, sort and write them back to fields with the help of Evaluate:

    vResult = Evaluate(|
        _Delimiter := "#";
        _ListAll := @Sort(List1 + _Delimiter + List2 + _Delimiter + List3);
        FIELD List1 := @Word(_ListAll; _Delimiter; 1);
        FIELD List2 := @Word(_ListAll; _Delimiter; 2);
        FIELD List3 := @Word(_ListAll; _Delimiter; 3);
        ""|, doc)
    

    Choose a delimiter which won't be appear in lists.