Use Xpath to retreive list containing name from variable

I'll try to explain my situation as clear as possible. There a patients and doctors. Patients have null or one doctor assigned. Doctors have null or more patients assigned. I now need a microflow to calculate the number of patients assigned to a doctor. This number is shown as an attribute of the entity doctor. My idea to calculate this was using a microflow. First I want to retrieve a list of patients assigned to a specific doctor. Then count the number of patients on the list etc. I wanted to retrieve this list by using an Xpath expression. I've tried several commands but none seem to work. I believe the problem is the fact DoctorAssigned is not an attribute of Patient, but it's an association. Suggestions would be appreciated much! Thanks in advance, Max Edit: A sample of the domain model I'm using: Link to Image (Can't get the picture in this message, sorry) For some reason I can't perform the retrieve by association action in the microflow. The association doctor_patient is not listed to choose. I can however choose retrieve from database and retrieve the list that way. By retrieving from database all patients are retrieved instead of the only the ones assigned to the doctor. The parent of the association is the patient. The multiplicity is as it should be: [1-*] One 'Doctor' object is associated with multiple 'Patient' objects. Counting by using the web client is no option, because the number computed by the microflow has to be entered in the object Doctor. Edit [2]: Thanks, i've got it working now. I've used the Xpath constraint: [Module.Patient_Doctor = $Doctor]
2 answers

You can do this using a microflow, or directly in the web client. To do it in the web client with no microflow, add an attribute (called Counter) of type integer to your patient entity and set the default value to 1. You can then show a datagrid of patients on your Doctor record using the association, and use the aggregate function on the column properties of the Counter column to sum the rows and give a total count.

To do this in a microflow, perform a retrieve action using the association (retrieve patients with [module.Patient_Doctor = $Doctor]). Having got a list returned (PatientList) you can perform a List Aggregate Function to perform a count of the rows and return an integer variable.

Edit after additional information: The association you want for the retrieve action is Patient-Doctor not Doctor-Patient. When you add a Retrieve action to your microflow, by default it will be set to Retrieve by association. This will not work for you in this situation. You need to change the radio button to retrieve From Database and select the Patient entity to retrieve from. You can then build a query in square brackets like [Module.Patient_Doctor = $Doctor]. That should get you past your first hurdle.


Just retrieve all patients which are associated to your specific doctor. Count the list and return this variable in your microflow. Use this microflow in a virtual attribute in your doctor entity.

Could you tell us what your exact problem is? You said: I've tried several commands but none seem to work.

What doesn't work? The retrieve?