Query Entity Issue

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

Parents
  • 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)
    )
    )
    )
Reply
  • 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)
    )
    )
    )
Children
No Data