Use list as filter in Aggregate

Hi All,

I'm making a app for leave management. Each employee can be in multiple divisions and have both an employee or manager role(outside the usersystem of Outsystems because of flexibility).

This is my filtered aggregate where i select the divisions where the user is manager. This i append to a list (Division structure).


Now comes the difficulty. The next aggregate i make is to filter all leaveapplications where division is one of the members in the list.


Can anyone help me out here. Thanks in advance.


Jan

Hi Jan,

Is there a reason why you want to do this in 2 steps, first producing the list of divisions and then using that list as input to your next aggregate ?

If I'm reading this correctly, your aim is to retrieve all leave applications of employees that are in divisions that a given user is manager of, right ?

You can do this in a single aggregate, with the user/userextended entities appearing as source twice, once for the employee side and once for the manager side.

I don't have my laptop with me this week, so I can't make an example oml, but the joins in your aggregate would look something like

(Assuming you named your sources 'manager' and 'employee')

Manager.id = ManagerExtended.UserId

Division.Id = ManagerExtended.DivisionId

Division.Id = EmployeeExtended.DivisionId

Employee.id = EmployeeExtended.UserId

VerlofCore.UserId = Employee.Id

and your filter on the aggregate would look something like

Manager.id = InUserId

ManagerExtended.TypeUserExtendedId = 2

EmployeeExtended.TypeUserExtendedId = 1


Does this make any sense to you, not sure about the syntax 

Dorine


Ps a personal note on naming your entities.  

Since the entity you use to connect users with divisions is a many-to-many, 'extended' might not be the best choice, it could confuse other developers since it sounds a lot like a one-to-one extension entity.  I'd call it something like UserRoleInDivision. And VerlofCore doesn't really say what it is.  Maybe call it LeaveApplication.

Hi Dorine,


thanks for your reply, you are totally right about the naming of the entities. I'm going to change this tomorrow and will work on your solution. I will get back to you tomorrow.


Jan



Dorine Boudry wrote:

Hi Jan,

Is there a reason why you want to do this in 2 steps, first producing the list of divisions and then using that list as input to your next aggregate ?

If I'm reading this correctly, your aim is to retrieve all leave applications of employees that are in divisions that a given user is manager of, right ?

You can do this in a single aggregate, with the user/userextended entities appearing as source twice, once for the employee side and once for the manager side.

I don't have my laptop with me this week, so I can't make an example oml, but the joins in your aggregate would look something like

(Assuming you named your sources 'manager' and 'employee')

Manager.id = ManagerExtended.UserId

Division.Id = ManagerExtended.DivisionId

Division.Id = EmployeeExtended.DivisionId

Employee.id = EmployeeExtended.UserId

VerlofCore.UserId = Employee.Id

and your filter on the aggregate would look something like

Manager.id = InUserId

ManagerExtended.TypeUserExtendedId = 2

EmployeeExtended.TypeUserExtendedId = 1


Does this make any sense to you, not sure about the syntax 

Dorine


Ps a personal note on naming your entities.  

Since the entity you use to connect users with divisions is a many-to-many, 'extended' might not be the best choice, it could confuse other developers since it sounds a lot like a one-to-one extension entity.  I'd call it something like UserRoleInDivision. And VerlofCore doesn't really say what it is.  Maybe call it LeaveApplication.

Hi Dorine,

I've tried the solution in a couple of ways, without a working result.


This is what i have at the moment:

I still get a couple of sequencing results without other users than myself.

Hi Jan, 

Can you show what is in your database and what is in you aggregate result.

It looks ok to me on first sight.

If you can't share data, i'm home tomorrow night and will try to make an example oml.

Have you tried playing with the join options.  It feels to me that you only want resulting rows that have a record in each of your joined tables, so I think it should work with all options set to 'only with'

Dorine Boudry wrote:

Hi Jan, 

Can you show what is in your database and what is in you aggregate result.

It looks ok to me on first sight.

If you can't share data, i'm home tomorrow night and will try to make an example oml.

HI Dorine, 

I will post my output tomorrow, if you can show me an example I will be very happy :). 


Hi Jan,


see attached oml.

My datamodel isn't exactly like yours, I didn't add the IsActive to LeaveApplication.  Also I involved 2 extra entities in the query to also retrieve the partOfDay and the Status of the Application.


When I test, it works as I expect.  I've tested variations as one person managing several departments, several people managing the same department, someone being both manager and employee of the same department, all show me result as exptected.

For example, Jack Daniels is manager of Sales and Marketing, and in Marketing he's not alone, there is also another manager there.  Paul from Marketing and  George from Sales show up on Jacks page, other manager only sees Paul from Marketing, and both don't see any Applications of IT department.



Can you see any difference with your query (other than the IsActive) ?  Let me know if you find anything, I'm curious what is going on.


So the first 3 menu items are just scaffolded to edit database, no logic in them.  And the 4th menu item "demo manage leave applications" holds the query and shows the leave applications to be managed by the currently logged on manager.


Dorine

Hi Dorine,


There are a couple of changes in the structure. In my database i have one field to link to the user, in your leave table ther is also a link to the one that managed the leave (i.m.o. that is much better because of the audit trail). 

I can't find any other difference between the tables and the structure. I'm going to build the datastructure again from scratch to get a new starting point :). Thanks for your help Dorine. I will use your datastructure as the starting point and will try to recreate it.


Jan

Hi Jan,

I just made this example data model to show how to build the aggregate.  I'm not sure if you are building an app to gain experience or if it's actually intended to be used.  If so, it's probably a bit too simple and there should go some more consideration into it.

For example, you're talking about audit trail, but maybe an application goes through several statusses before getting approved or declined, you might want to record each status with timestamp and user, so a single relationship won't do.  Also, an employee is not necessarily the same thing as a user of the system, I'd probably choose to model the employee as it's own entity, with a relationship to user.  And so on...