Issue with sorting and filtering a list in a DS microflow to a data grid

Hi,   I have a Medical Event entity and Patient entity (many to one association) . I have retrieved medical event list from database with sorting order of  patient ID, but the issue is I need to filter this list based on selected BU again (as shown in screenshot below) .so after filtering the sorting is not working. I couldn’t find other option to sort with PatientID( not in scope) in the list operation at the end.  Could you please suggest any way  
1 answers

Can you add an PatientID attribute to MedicalEvent and then maybe create and run a conversion microflow which retrieves all the  medicalevents and then uses a loop to iterate over each and retrieve the associated patient and then fills in the PatientID attribute in MedicalEvent with the one from Patient? 


So it would look like this (to avoid committing in loops): Retrieve (MedicalEventList). → [Loop (MedicalEventIterator): Retrieve Patient over association → ChangeObject (MedicalEvent) Set(PatientIDME = PatientID) no refresh/no commit) and then commit the medicaleventlist after the loop. 

You can then sort based on patientID. You could name the new attribute _PatientID (with the underscore). That reads as a helper attribute (best practices).

There are other ways im sure but this is one as well.