Sorting on subtable

Hello! Can someone confirm: we cannot sort when we loop through a subtable, correct? I do not see any indication that we can.

That is correct, you cannot sort subtable records right now.

1 Like

Some workarounds I can think of and have used in this space which might be helpful:

  • if you don’t want to modify the data in the subtable, a regular Fetch Records directly against the subtable and pass in a filter of nwHeaderId = the nwId of the regular record and then a sort as specified
  • if you want to permanently reorder the records in the subtable
    • create a temp table based on the subtable
    • loop the subtable and insert a record in the temp table for each record in the subtable
    • delete all records in the subtable
    • fetch the temp table in with a sort applied and re-insert the records in order into the subtable
3 Likes

Is that in the plans anywhere soon? @joeyates23

Ian I am going to book a meeting with you to get some input @ian.p

1 Like

I don’t believe that’s a change we’re considering at this time, but if there’s a use case for it, please feel free to work with partner or customer support and enter an idea.

@ian.p’s suggestions are all correct and will lead you in the right direction for getting the right record(s), so long as the subtable is of type Main. If not, the Fetch suggestion will not work.

If what you’re working on is early enough in the development process, you can always consider a different data structure like a Header-Detail or manually controlling the relationships between tables. Many things are possible, so feel free to post more details or clarifying questions about what the most performant solution might be.

There’s also this thread, Is it possible to sort a sub table?, which goes into some more detail on the matter.

3 Likes

Yes, I think H/D would have made a lot of sense here but unfortunately this was coded a long time ago and I am sure they had there reasons. I am going to go down the temp table route and see if that works for me. Thanks everyone!

1 Like