Skip to main content
sameeru0003
Known Participant
May 24, 2023 6:42 AM UTC
Question

Expression for sorting a list equivalent to OrderBy and ThenBy equivalent of C#

Hi,

I am facing one challenge to sort a list of addresses into particular order. The appian sail expression should match the sorting order as in our C# equivalent using orderby and thenby. My SAIL expression is not giving same results as C# code(Expected one).Kindly provide suggestions.

in c#:

sortedAddresses.AddRange(addresesList.Where(x => x.AddressId != primaryAddress.AddressId).OrderByDescending(o => o.EndDate).ThenByDescending(o => o.EffectiveDate).ThenBy(o => o.AddressType.Name).ThenByDescending(o => o.IsActive).ToList());

in SAIL:

todatasubset(
todatasubset(
todatasubset(
todatasubset(
remove(
local!7sortedaddresses,
wherecontains(
touniformstring(local!primaryAddress.addressId),
touniformstring(property(local!data, "addressId", ""))
)
),
a!pagingInfo(
startIndex: 1,
batchSize: - 1,
sort: a!sortInfo(field: "endDate", ascending: false())
)
).data,
a!pagingInfo(
startIndex: 1,
batchSize: - 1,
sort: a!sortInfo(
field: "effectiveDate",
ascending: false()
)
)
).data,
a!pagingInfo(
startIndex: 1,
batchSize: - 1,
sort: a!sortInfo(field: "addressType", ascending: true())
)
).data,
a!pagingInfo(
startIndex: 1,
batchSize: - 1,
sort: a!sortInfo(field: "isActive", ascending: false())
)
).data

1 reply

stefanhelzle0001
Brainy
May 24, 2023 6:58 AM UTC

Each todatasubset sorts the whole list only by that field you provide. Find examples of how to sort by multiple fields in the documentation.

docs.appian.com/.../fnc_scripting_todatasubset.html