# How to create an automatic relation based on a number of different criteria

**URL:** <https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140>\
**Category:** Get Help\
**Created:** [March 16, 2023, 10:51pm UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140 "2023-03-16T22:51:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![billyjackson](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/billyjackson/32/6345_2.png) [@billyjackson](https://community.fibery.io/u/billyjackson)\
**Post date:** [March 16, 2023, 10:51pm UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/1 "2023-03-16T22:51:37Z")

</div>

I’m using the fantastic Gmail integration, and I’m looking to use some light CRM-like functionality by displaying all the emails with a client inside their Contact entity. Unfortunately, I can only seem to easily create an automatic relation between them and those messages with their email in the “Email From” field.

to link to messages TO them, I can create a lookup from Contact → Gmail Contact → Message, but this field is then displayed in a separate list inside the entity.

The functionality I’d like to have would be a single list with both Messages To and Messages From, sorted by date together - in much the same way you can include two first-level databases in a list.

If anyone has any advice, that would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![tpaktop](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/tpaktop/32/6394_2.png) [@tpaktop](https://community.fibery.io/u/tpaktop)\
**Post date:** [March 17, 2023, 4:00am UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/2 "2023-03-17T04:00:46Z")

</div>

You would need to combine multiple lists in one.  
There was a [topic](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/33) for that sometime ago. At the end there is an instruction from @Matt_Blais on how to make it work.  
TLDR:  
Two of your lists would be automatically linked based on from/to. You can hide those lists from UI as they are only used in automation.  
Automations would sync those two lists into one by adding and removing links when lists are updated.

Having `union` function would be way nicer though /cc @Chr1sG

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [March 17, 2023, 7:11am UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/3 "2023-03-17T07:11:59Z")

</div>

> [@tpaktop](#):
>
> Having `union` function would be way nicer though /cc @Chr1sG

The union function is in the backlog, but I’m not sure when it might get implemented I’m afraid.

> [@How to union two list fields in the same Database?](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467):
>
> I have two list fields in my Database: Tags and [Project Tags]. (Tags is an x:many relation and [Project Tags] is a lookup of an x:many field.) I want to combine them into a single list field [All Tags], so if (eg) Tags = (foo, bar) and [Project Tags] = (baz, bam) then [All Tags] = (foo, bar, baz, bam). Is this possible? I can’t figure out how to do it with a formula or a lookup. Extra complication: ultimately I actually want the unique set of all tags, so if (eg) Tags = (foo, bar) and [Pro…

---

<div class="post-metadata">

**Author:** ![billyjackson](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/billyjackson/32/6345_2.png) [@billyjackson](https://community.fibery.io/u/billyjackson)\
**Post date:** [March 17, 2023, 7:25pm UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/4 "2023-03-17T19:25:14Z")

</div>

Thank you both! Will use an automation in this case.

Not sure if you have an internal list of requests for Union, but would love to add a +1 to it if it existed: There are a number of use cases where we could benefit from this.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [March 17, 2023, 8:15pm UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/5 "2023-03-17T20:15:40Z")

</div>

> [@billyjackson](#):
>
> would love to add a +1 to it if it existed

Consider your vote now counted 🙂

---

<div class="post-metadata">

**Author:** ![billyjackson](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/billyjackson/32/6345_2.png) [@billyjackson](https://community.fibery.io/u/billyjackson)\
**Post date:** [March 21, 2023, 3:09am UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/6 "2023-03-21T03:09:59Z")

</div>

Another question:

Having successfully implemented this across multiple Email Accounts (each with 3x fields connecting each Contact to each Email, with a different database for each email accounts messages), I’m running into another difficulty:

I’m looking to create a single list view that shows all the emails from every inbox, inside of the associated Contact entity views.

The problem is that each Contact entity has the following relations:

1. Emails From Person A
2. Emails To Person A (A lookup only, via Gmail Contacts)
3. Emails (To+From Combined, created by automation) Person A
4. Emails From Person B
5. Emails To Person B (A lookup only, via Gmail Contacts)
6. Emails (To+From Combined, created by automation) Person B
7. etc. for add’l inboxes

And when I go to create a list view within a contact entity and try to include multiple “First Level” databases for target Emails To+From, both Person A and Person B, there is no ability to tell the UI which relation I’m referring to. Sometimes, I get both relation I’m looking for (Emails To+FroM). Sometimes, it seems like I get the wrong one (Emails To+From Person A; Emails From Person B).

Is this the intended functionality and I am thinking about this incorrectly, or is there a functionality limitation here for interacting with multiple different relations between the same two entities?

---

<div class="post-metadata">

**Author:** ![billyjackson](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/billyjackson/32/6345_2.png) [@billyjackson](https://community.fibery.io/u/billyjackson)\
**Post date:** [March 22, 2023, 7:47pm UTC](https://community.fibery.io/t/how-to-create-an-automatic-relation-based-on-a-number-of-different-criteria/4140/7 "2023-03-22T19:47:40Z")

</div>

I’ve moved this question to [this thread here](https://community.fibery.io/t/how-to-combine-first-level-entities-on-a-relations-list-view-inside-another-entity-when-there-are-multiple-sets-of-relations-between-all-the-entities/4173) for neatness reasons
