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
9 replies
Subscribers
7 subscribers
Views
6501 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Query Entity Issue
prakharg
over 7 years ago
I have a Query Entity rule which accepts input as appId of multiple type, from my SAIL UI I am calling this rule with appIds for example {1;2;3;4}, but query entity is not returning result in same order rather it is returning CDT in Random fashion as given below:
Actual Result - [Id =3, name="Tom"];[Id=4, name="Dan"];[Id=1, name="John"];[Id=2, name="David"]
Expected Result - [Id=1, name="John"];[Id=2, name="David"];[Id =3, name="Tom"];[Id=4, name="Dan"]
appIds are passed in sequence {1;2;3;4}
This issue is creating data mismatch on UI.
Is there a way to handle this?
Thanks in Advance
OriginalPostID-251314
Discussion posts and replies are publicly visible
0
Poorna Guduri
A Score Level 1
over 7 years ago
Hi prakhar,
Could you please check the value of "sortInfo" that you have configured while passing value to the "pagingInfo" parameter of the Query Entity rule. By configuring the sort as, field - "id" and ascending - true, you can achieve the expected result.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shashank
over 7 years ago
@prakharg
Hi ,
There is one way of doing it ,
You can sort the field which maps the "id" (appId in your case) in a!sortInfo() and mark ascending as true , so that you get the data in sequence {1,2,3,4} only , but this might not work for cases where you pass the appIds as {3,4,2,1} and expect the result to come in the same sequence
Something like this might work
=====
a!pagingInfo(
startIndex :
,
batchSize :
,
sort : a!sortInfo (
field : "appId",
ascending : true
)
=====
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
prakharg
over 7 years ago
@poornah Thanks for the reply, but if i provide sortInfo then it will not work in case IDs are passed as {4;3;2;1} as stated by shashank
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
prakharg
over 7 years ago
@shashank, I am looking for all the cases, IDs can be passed in any sequence and i want result in exact same sequence in which IDs are passed
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
To get the results in the same order as the IDs are you have to add a bit more magic. You have to remap the results with the provided IDs. Like this:
=with(
local!data: if(
isnull(ri!ids), null,
/* Get the items matching the provided IDs */
/* Result will be in the order the entities are stored in DB */
a!queryEntity(YOUR QUERY),
if(isnull(ri!ids),
null,
/* For each item in the list of indexes return the entity on that index */
index(local!data.data, apply(
/* This creates a list of indexes of where the entity is within data */
/* but in the same order as the IDs provided */
lookup(local!data.identifiers, _, null), ri!ids), null)
)
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
sikhivahans
over 7 years ago
I believe, the following could be another option:
fn!apply(
fn!displayvalue(
_,
local!ds.data.id,
local!ds.data,
null
),
ri!ids
)
Also, I guess you may need to remove null values in the resultant output if you are following the strategies mentioned (by me and I think @stefanh's approach as well) above, as you might not be having the results always for a given set of inputs.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
PhilB
A Score Level 1
over 7 years ago
Why dont you sort the IDs before passing them in, and then sort on ID during the query entity?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
prakharg
over 7 years ago
Thanks @stefanh Magic worked.
Thanks @sikhivahans
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
You are welcome :-)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel