Searching for items based on a parent thing's list of those items?

My app has data types of Project and Action.

The Project type has a field, Actions, that is a list of type Action.

Action also has a Project field pointing to its Project.

When adding a new Action for a Project, the app needs to determine the highest value PosnInProject for all Actions already belonging to the Project. This is to assign a value to PosnInProject that will put the new Action at the end of the Project’s list of Actions. Here’s how it currently looks:

The way I read this, it will be highly inefficient since it will search all Actions for those with Project matching the parent Project.

What I think I should be doing is getting the Project record and searching its list of Actions to find the maximum PosnInProject value. Trouble is, I don’t know how to construct this.

Any help is appreciated.

Update after original post:

After posting this, I tried something that just seemed too obscure as I thought about it and wrote it:

image

This seems to work, i.e. gives me the right answer. Is it the best way to approach this?

since you have a list of actions in project why don’t you just say 'parent group actions:max+1 ’ could be the same with the dropdown if the dropdown in fetching from ‘parent project actions’

1 Like

Yes, the dropdown value is the Project, parent of the Actions, so I think I’m doing what you suggest. Thanks.

1 Like