Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
10 replies
Subscribers
6 subscribers
Views
5641 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
Process
Hi, I am trying to sort a text array and tried using the following recipe.
Howard
over 10 years ago
Hi,
I am trying to sort a text array and tried using the following recipe.
forum.appian.com/.../Function_Recipes.html
Since this is just an array, not a record type, I am not sure what to put in as the field name to sort on in the data input tab. When I try to put in "field" as the value, I get an error evaluating expression. Any ideas? Thanks.
An error occurred while evaluating expression: departmentNameList:todatasubset(#"_a-0000d27e-8161-8000-8fc8-0a000064044c_72737",ac!pagingInfoNodeInput2).data (Expression evaluation error at function 'todatasubset': Error evaluating function 'todatasubset' : java.lang.IllegalArgumentException: The given data type is not a record type...
OriginalPostID-124071
OriginalPostID-124071
Discussion posts and replies are publicly visible
Top Replies
Mike James
over 10 years ago
+1
Certified Lead Developer
The sorttextarray() function is part of the Sort Utilities Plugin: forum.appian.com/.../summary
0
Dan Lluhi
Certified Lead Developer
over 10 years ago
Hey, if you haven't figured it out, try something like this :
load(
local!textArray: {
"b",
"a"
},
local!tempCDT: apply(
rule!toCDT,
local!textArray
),
local!pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1,
sort: a!sortInfo(
field: "field",
ascending: true
)
),
todatasubset(
local!tempCDT,
local!pagingInfo
).data.field
)
rule!toCDT has one rule input called "text" (Type: Text), and is defined as:
{field: ri!text}
replace local:textArray from the first rule with the text array that you want to sort.
Basically what the code does is converts your text array to a temporary "CDT" which just has one field (called field), that way when you make your pagingInfo you can give it a field to sort on. In the example above, the result is {"a","b"}
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Howard
over 10 years ago
I did try your method and I am still getting the same error message when I test the rule. We are using v7.3
Expression evaluation error at function 'todatasubset' [line 18]: Error evaluating function 'todatasubset' : java.lang.IllegalArgumentException: The given data type is not a record type: Dictionary (id=94)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Howard
over 10 years ago
When I remove the pagingInfo information, it works but the data is not sorted.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Dan Lluhi
Certified Lead Developer
over 10 years ago
Could you share the piece of code you're trying to run? Specifically how you're calling todatasubset?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Howard
over 10 years ago
I am using the same code that you had posted.
load(
local!textArray: {
"b",
"a"
},
local!tempCDT: apply(
rule!toCDT,
local!textArray
),
local!pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1,
sort: a!sortInfo(
field: "field",
ascending: true
)
),
todatasubset(
local!tempCDT,
local!pagingInfo
).data.field
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Dan Lluhi
Certified Lead Developer
over 10 years ago
Strange, it works fine when I run it. However, I am using 7.5, so that might be the difference. Looking at the documentation for todatasubset at
forum.appian.com/.../Scripting_Functions
it says that the first parameter (arrayToPage) can use dictionary syntax, which is what is happening in my example above. However it does say towards the end "Sorting is only supported for complex data types and is not supported for a dictionary array." which is probably what is causing the error you are seeing. If that's the case, I'm not sure how it works for me, but there is another workaround you could try.
Instead, create a CDT for this purpose specifically, which only has one field (a text field to store the text value you want to sort). and instead of returning {field: ri!text} in rule!toCDT to create a dictionary, return type!yourCDT(field: ri!text) to create an instance of this new CDT. Alternatively, if you dont want to create a new CDT, you could use an existing CDT that has a text field. For example, if you had an Employee CDT with a field for "name", you could define rule!toCDT as :
type!Employee(name: ri!text), and change the rest of the code to the following:
load(
local!textArray: {
"b",
"a"
},
local!tempCDT: apply(
rule!toCDT,
local!textArray
),
local!pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: -1,
sort: a!sortInfo(
field: "name",
ascending: true
)
),
todatasubset(
local!tempCDT,
local!pagingInfo
).data.name
)
Hope this helps!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Dan Lluhi
Certified Lead Developer
over 10 years ago
Looking a bit more into the documentation, looks like sorting using the Dictionary syntax is a feature that was added for 7.4. So you'll have to use the CDT method from my most recent post if you're on 7.3.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Howard
over 10 years ago
I had to use the CDT method to get the array sorted. Thank you for your help.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Chris
over 10 years ago
Also, Appian does include a sorttextarray() function for normal text arrays.
Cancel
Vote Up
-1
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike James
Certified Lead Developer
over 10 years ago
The sorttextarray() function is part of the Sort Utilities Plugin:
forum.appian.com/.../summary
Cancel
Vote Up
+1
Vote Down
Sign in to reply
Verify Answer
Cancel