Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
+1
person also asked this
people also asked this
Replies
8 replies
Answers
1 answer
Subscribers
7 subscribers
Views
12753 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
General
Is there any way to sort text array in Appian, without using a plugin?
komalk
over 8 years ago
Is there any way to sort text array in Appian, without using a plugin?
OriginalPostID-170628
OriginalPostID-170628
Discussion posts and replies are publicly visible
Top Replies
Dan Lluhi
over 8 years ago
+1
Certified Lead Developer
Hi, The todatasubset function ( forum.appian.com/.../Scripting_Functions.html can be used to sort data OOTB. According to the documentation sorting is only supported for CDTs, so you'll want to use a list…
KARTHIK NATARAJAN
over 8 years ago
+1
Certified Lead Developer
Komal, Not sure if recommended but there is a hidden function sort(), which when used gives sorted text array in ascending order. Just call sort(ri!textArray) in your expression rule.
0
Dan Lluhi
Certified Lead Developer
over 8 years ago
Hi,
The todatasubset function (
forum.appian.com/.../Scripting_Functions.html
can be used to sort data OOTB. According to the documentation sorting is only supported for CDTs, so you'll want to use a list of CDTs for the arrayToPage parameter, and a!pagingInfo for the pagingConfiguration. Make sure the sort parameter of a!pagingInfo is filled out, and points to the CDT field that you want to sort on. Hope this helps!
Cancel
Vote Up
+1
Vote Down
Sign in to reply
Verify Answer
Cancel
0
komalk
over 8 years ago
Yes it worked.. Thanks Daniell
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 8 years ago
@komalk To the best of my knowledge, this can be done OOTB without any plugin or CDT.
We can accomplish the requirement by taking advantage of the Appian's Complex System Data Type namely 'LabelValue' (https://forum.appian.com/suite/help/7.10/Appian_Data_Types.html#LabelValue) which is present OOTB and thereby we can avoid depending on a CDT as well. Here is the rule for doing so:
Name:
sortTextArray
Input(s):
1. textArray (Text Multiple)
2. isAscending (Boolean)
Output:
sorted text array (textArray is not empty) or null (if textArray is null or empty)
Definition:
if(
\trule!APN_isEmpty(array:ri!textArray),
\tnull,
\twith(
\ tlocal!arrayOfLabel:fn!apply(type!LabelValue(label:_),ri!textArray),
\ tlocal!sortedDataSubset:fn!todatasubset(
\ tarrayToPage:local!arrayOfLabel,
\ tpagingConfiguration:a!pagingInfo(startIndex:1,batchSize:-1,sort:a!sortInfo(field:"label",ascending:ri!isAscending))
\ t),
\ tlocal!sortedTextArray:fn!property(local!sortedDataSubset.data,"label",null),
\ tlocal!sortedTextArray
\t)
)
Ex1: rule!sortTextArray(textArray:{"Pega","Appian","Lombari","Bonita"},isAscending:fn!true()) --> Appian; Bonita; Lombari; Pega
Ex2: rule!sortTextArray(textArray:{"Pega","Appian","Lombari","Bonita"},isAscending:fn!false()) --> Pega; Lombari; Bonita; Appian
Attached the rule for your convenience.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
komalk
over 8 years ago
that was really helpful @sikhivahans... Thanks a lot!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
KARTHIK NATARAJAN
Certified Lead Developer
over 8 years ago
Komal, Not sure if recommended but there is a hidden function sort(), which when used gives sorted text array in ascending order. Just call sort(ri!textArray) in your expression rule.
Cancel
Vote Up
+1
Vote Down
Sign in to reply
Verify Answer
Cancel
0
michaelo199
over 8 years ago
Yes. SortTextArray ... you dont have to use a plugin
Cancel
Vote Up
-1
Vote Down
Sign in to reply
Verify Answer
Cancel
+1
sikhivahans
over 8 years ago
@karthik Correct, that's the function which I have seen earlier at /search?q=OriginalPostID-160006.
Correct me if I am not wrong, to implement the descending order, we might need to reverse the ascending ordered array as follows: fn!reverse(sort(ri!array)).
We need to see if Appian guarantees support to these kind of hidden functionalities. Anyhow fn!wherecontains() has also evolved from a hidden status as per my knowledge.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
0
KARTHIK NATARAJAN
Certified Lead Developer
over 8 years ago
@sikhivahans Yes Correct! reverse() will help us to sort in descending and i too guess the same about fn!wherecontains being hidden before its exposure!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel