Entity list view: Filter view

I have some relations between Meeting, Project, Task.

A Project can have many Tasks and many Meetings.
A Task can have one Project and many Meetings.
A Meeting can have one Project and many Tasks.

Whenever we have a Meeting, we also want to have Tasks connected to it. So we can add it directly in the Tasks view (image). And to make it automatically connected to the Meeting’s Project we can set up a Global filter. But this effects all other Projects as well. So I thought, can I filter by [This Meeting].Project instead, so it’s automatically connected to the right Project?

But I don’t see if this is possible?

It may be similar to this thread.

What do you mean by the ‘Tasks connected to it’?
Based on how you have described your relations

a Task could be linked directly to a Meeting (many-to-many), but can also be inferred as being related to a Meeting because it shares the same parent Project.

If you want to show the Tasks indirectly related to the Meeting, you could create a lookup, but this would be a read-only field.

The Tasks field you are showing in the image above represents the direct relation by default.
If you want to change the relation view to be context filtered to show indirectly related Tasks (= those Tasks owned by the Project that the Meeting is owned by) then it is not possible for the reasons explained here:

What do you mean by the ‘Tasks connected to it’?
Based on how you have described your relations

That Task has a many-to-many relation with Meeting.

Task also has a direct relation to a Project.

But if I understand it correctly I can’t have a global filter on the Task relation view that says:

Project is [This.Meeting].Project

and instead have to select an individual project?

@Chr1sG I think I may be asking for formulas in filters, similar to this one perhaps:

And if not possible now, if there’s a workaround.

Well, I would take a step back and ask the question: what is the meaning of having two relations between Task and Project (one direct and one indirect)?

Can a Task belong to a Meeting but not belong to the Project that the Meeting relates to?
Can a Task belong to a Project but not belong to all the Project’s Meetings?

What is the flow for users in terms of when/how Tasks are created?

TLDR
A simple way to create Tasks within a Meeting, that is automatically associated to a Project.

Description

Can a Task belong to a Meeting but not belong to the Project that the Meeting relates to?

Yes (in practice right now). But we would like a Task to always be connected to a Project. So this is done manually right now (if it’s created in a view that does not set the Project at creation).

Can a Task belong to a Project but not belong to all the Project’s Meetings?

Yes.

What is the flow for users in terms of when/how Tasks are created?

Basically one of these:

  1. Within a Project, create a Task. E.g within the Project “Clean the office” have the Tasks “Clean windows”, “Clean floor”, e.t.c.
  2. Within a Meeting (that is connected to a Project), create action items (Tasks). E.g. within the Meeting “Review of office cleaning” have the Tasks “Clean windows again, missed a spot”

I have already made a button within a Meeting that automatically sets the Project based on the Meeting’s related Project. And it works fine.

But if you look at the first image in this thread I’m looking for a way to create a Task from the Task relation view and have it set the Project automatically.

Do you mean that you have an automation that sets the Project for a Task whenever that Task is created in a Meeting?

If so, I don’t know why you think you need this

Do you mean that you have an automation that sets the Project for a Task whenever that Task is created in a Meeting?

No I have a button, like this image

But do you think it would be possible to do what you suggest?

Basically, I’m asking this for my team members. I know of the limitations that currently exist and can go to the button whenever I want to create a Task from a Meeting. But since the software allows for creation of tasks from many different places and it says “Link or Create” you expect the Task to be connected to the Meeting’s Project as well.

image

OK, I suspect you need an automation like this:

This will be triggered if a Task is created in a Meeting’s relation field (since the Task is effectively being linked to the Meeting immediately on creation).
It will link the Task to the Project that the Meeting belongs to.

But note, if you were to move a Task from one Meeting to another, and the second Meeting belonged to a different Project, the Task would be switched from the first Meeting’s Project to the second’s.
I guess this may not happen very often, but you need to think if this is the behaviour you want.

There is basically no easy fix for this issue, since the current database relations allow for a Task to be linked to multiple Meetings, and yet these Meetings might not belong to the same Project.

Thanks, it works fine!

I added “Project is empty” as a condition for running the automation. When I changed Meeting it did not trigger the automation.

Yeah, that is one way of ensuring that a Task doesn’t accidentally change Project if it is added to another Meeting.
But still begs the question of how to resolve if a Task is linked to multiple Meetings each with a different parent Project… :person_shrugging:
Hopefully, it is a largely theoretical question :crossed_fingers:

Yes, I actually changed the relation so that a Task can only be connected to one Meeting. There was no need for a many-to-many relation to begin with.

1 Like

Then I guess the automation will need to change:

Yes, already changed :slight_smile:

But good for anyone else to see as well.

1 Like

FYI it’s also possible when creating an inline entity in a Rich Text field (via Ctrl/Cmd+E) to automatically link the new entity to the one you are working within (i.e. the entity containing the Rich Text) or some other related entity.

This does require some more complex scripting though:


// If a Task's "Project" field is uninitialized, and there is a "Meeting Notes"
// that references the Task, set the Task's "Project" field from the MN's "Default Project".

// Script parameters
const ENTITY_LINK_FIELD = 'Project'          // Task field that needs to be set
const PARENT_TYPE       = 'Project/Project'  // Type we want to find a link to (value for)
const REF_ENTITY_TYPES  = ['Clients/Meeting Notes']  // Types that have a "Default Project" field
const REF_ENTITY_LINK_FIELD = 'Default Project'  // Name of the field to copy

const fibery = context.getService('fibery')
// const log = console.log

for (const entity of args.currentEntities) {
    // Set the Project field only if empty
    if (entity[ENTITY_LINK_FIELD].id !== null) { continue }
    // Get all references to the Task
    const entityWithRefs = await fibery.getEntityById(entity.type, entity.id, ['References'])
    // Look for a reference to a type with a "Default Project" field (i.e. Meeting Notes)
    for (const ref of entityWithRefs['References']) {
        // Get referencing doc
        const refDoc  = await fibery.getEntityById('Collaboration~Documents/Reference', ref['Id'], ['FromEntityId', 'FromEntityType'])
        const refType = refDoc['FromEntityType'].name
        if (refType == PARENT_TYPE) {
            // The referring entity is the actual PARENT_TYPE (so its ID can be used directly)
            // I.e. a Task was created/referenced in a Project's Rich Text field, so we know the Project
            const refEntity = await fibery.getEntityById(refType, refDoc['FromEntityId'], ['Name'])
            // log(` refType == PARENT_TYPE: ${refType}, ${refDoc['FromEntityId']} ${refEntity.id}`)
            await fibery.updateEntity(entity.type, entity.id, { [ENTITY_LINK_FIELD]: refEntity.id })
            break
        } else if (REF_ENTITY_TYPES.includes(refType)) {
            // Found a suitable referring entity (i.e. that has a "Default Project" field)
            const refEntity = await fibery.getEntityById(refType, refDoc['FromEntityId'], ['Name', REF_ENTITY_LINK_FIELD])
            if (refEntity != null && refEntity[REF_ENTITY_LINK_FIELD].id != null) {
                const refId = refEntity[REF_ENTITY_LINK_FIELD].id
                await fibery.updateEntity(entity.type, entity.id, { [ENTITY_LINK_FIELD]: refId })
                break
            }
        }
    }
}


1 Like

That’s nice, thanks for sharing!

Actually, I think they should be automatically linked when created if there exists a relationship that is one-to-many.