'Lotusscript Sorting String Array

I'm trying to sort a string Array which is a result of two Array lists (Added and Changed Dates).

combinedAddChangeDates = FullTrim(ArrayAppend(ChangeDate,addDate))

vResult = Evaluate (|@Sort(combinedAddChangeDates)|)

I'm getting nothing as vResult. Can you please help me?

The value of combinedAddChangeDates are as follow:

  • [1] "22/04/2022-01:00 PM-06:00 PM-Changed"
  • [2] "23/04/2022-01:15 PM-06:00 PM-Changed"
  • [3] "06/04/2022-08:00 AM-06:00 PM-Added"

I want to sort them according to their string date:

  • [1] "06/04/2022-08:00 AM-06:00 PM-Added"
  • [2] "22/04/2022-01:00 PM-06:00 PM-Changed"
  • [3] "23/04/2022-01:15 PM-06:00 PM-Changed"

Is this possible in Lotusscript? Thank you so much.



Solution 1:[1]

The Evaluate function doesn't recognise LotusScript variables, so when you do Evaluate(|@Sort(combinedAddChangeDates)|), it sees combinedAddChangeDates as an undefined variable with the default value of an empty string.

To use a LotusScript variable in Evaluate, you have to convert the variable to a string and append it to the formula with delimiters so that the formula sees it as a literal value.

Furthermore in the case of an array, you have to represent the array as a literal formula-language list, with elements separated by colons. The following should work:

vResult = Evaluate(|@Sort("| + Join(combinedAddChangeDates, |":"|) + |")|)

An alternative is to implement a pure LotusScript sorting function, so you don't call Evaluate at all. There may be examples of this elsewhere on the internet.

This solution just sorts the array elements as strings, and ignores the fact that your data contains dates. Sorting based on dates is much more complicated when you have string data: you'd need to extract the date part from each element, convert that to an actual date/time data type (e.g. with the LotusScript CDat function), build and sort a new array from the date/time data, then join the sorted dates back to the text parts ("-Added" or "-Changed") if you still need those parts.

I haven't provided code for the date-sorting, because that will take longer than I have time for.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1