# Link entity in rich field text

**URL:** <https://community.fibery.io/t/link-entity-in-rich-field-text/4138>\
**Category:** Get Help\
**Tags:** automations, rich-text\
**Created:** [March 16, 2023, 3:19pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138 "2023-03-16T15:19:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![YvetteLans](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yvettelans/32/6101_2.png) [@YvetteLans](https://community.fibery.io/u/YvetteLans)\
**Post date:** [March 16, 2023, 3:19pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/1 "2023-03-16T15:19:37Z")

</div>

Hi,

I have a use case where it would be really helpful to show a linked entity in a rich text field.

**Context**  
We build a content hub for solopreneurs in Fibery. They are not used with working in Fibery / databases / all the advanced stuff etc. So we try to make everything as simple as possible.

**Use case**

- User creates a Content item in the content database
- We have an automation button to ‘repurpose the content’
- When user clicks, we create a duplicate

**Question**  
It would be really helpful to show in the description which entities are linked, instead of showing the database.

Because one piece of content can be duplicated many times, and therefor it can be a child or parent or both. It will then show like this and that can feel a bit overwhelming for our customers:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/d/d71afcdba084e2e9a7fe9b9dde93aafb289bdf78.png)

If possible, i want to hide the databases and instead only show the linked entities in rich text field like this.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/d/db46a5a75282d89d42737c51b69b0c9a26c89a1f.png)

I think this should be somehow possible with the Append function in the automation but I’m getting stuck with the markdown template for the linked entity items 🥲

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/d/de16d28c3d635a580731da024835610c12b43fb6.png)

Does somebody have a great solution/script/idea for this?

Thanks!

---

<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 16, 2023, 3:27pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/2 "2023-03-16T15:27:06Z")

</div>

It’s possible, but not particularly simple, to create mentions of entities using markdown.  
Check out this part of the user guide:  
[https://the.fibery.io/@public/User\_Guide/Guide/Markdown-templates-53/anchor=Mentioning-Entities-and-Users--92511af3-219c-4cf8-be03-dec1a717cdf2](https://the.fibery.io/@public/User_Guide/Guide/Markdown-templates-53/anchor=Mentioning-Entities-and-Users--92511af3-219c-4cf8-be03-dec1a717cdf2)

---

<div class="post-metadata">

**Author:** ![YvetteLans](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yvettelans/32/6101_2.png) [@YvetteLans](https://community.fibery.io/u/YvetteLans)\
**Post date:** [March 16, 2023, 3:39pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/3 "2023-03-16T15:39:01Z")

</div>

Thanks! I am starting to believe more and more that you are an AI robot. How can you be so fast 🤣

---

<div class="post-metadata">

**Author:** ![Polina\_Zenevich](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/polina_zenevich/32/480_2.png) [@Polina\_Zenevich](https://community.fibery.io/u/Polina_Zenevich)\
**Post date:** [March 16, 2023, 3:40pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/4 "2023-03-16T15:40:27Z")

</div>

Sometimes I have same doubts as well!  
The only explanation - Chris is too good to be a 🤖 (I hope…)

---

<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 16, 2023, 3:43pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/5 "2023-03-16T15:43:47Z")

</div>

`BEEP BOOP` 🤖

---

<div class="post-metadata">

**Author:** ![YvetteLans](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yvettelans/32/6101_2.png) [@YvetteLans](https://community.fibery.io/u/YvetteLans)\
**Post date:** [March 16, 2023, 3:48pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/6 "2023-03-16T15:48:35Z")

</div>

> [@Polina\_Zenevich](#):
>
> Chris is too good to be a 🤖

True story 🤣 ChrisGPT is way better than ChatGPT 😁

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [March 16, 2023, 8:03pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/7 "2023-03-16T20:03:05Z")

</div>

Just wait until we get ChrisGPT-4 😁

---

<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, 2:51pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/8 "2023-03-17T14:51:34Z")

</div>

Here’s a script that will append #mentions to linked items.  
It can be triggered when an item is linked or unlinked, since it relies on clearing any previous #mentions and replacing them with the new needed ones.  
It assumes that you have a many-to-many self-relation, with fields called ‘Parent’ and ‘Child’.  
I hope it’s useful, or at the very least, inspirational.

```auto
const fibery = context.getService('fibery');
const schema = await fibery.getSchema();

for (const entity of args.currentEntities) {
    //get DB ID for later
    const dbID = schema['typeObjects'].filter((obj) => obj.name == entity.type)[0]['id'];

    //get info from entity
    const entityPlus = await fibery.getEntityById(entity.type, entity.id, ['Description', 'Parent', 'Child']);

    //get the current document contents
    var doc = await fibery.getDocumentContent(entityPlus['Description']['Secret'], 'md');
    
    //strip any previous linked items
    const position = doc.search(/\n\n\*\*Linked items:\*\*/);
    var newDoc
    if (position > 0) {
        newDoc = doc.substring(0, position);
    }
    else {
        newDoc = doc;
    }

    //append mentions of linked parents or children, if any
    if ((entityPlus['Parent'].length > 0) || (entityPlus['Child'].length > 0)) {
        newDoc = newDoc + ('\n\n **Linked items:**');
        for (const parent of entityPlus['Parent']) {
            const mention = '\n[[#^' + [dbID] + '/' + [parent.Id] + ']]';
            newDoc = newDoc + mention;
        }
        for (const child of entityPlus['Child']) {
            const mention = '\n[[#^' + [dbID] + '/' + [child.Id] + ']]';
            newDoc = newDoc + mention;
        }
    }
    await fibery.setDocumentContent(entityPlus['Description']['Secret'], newDoc, 'md');
}

```

---

<div class="post-metadata">

**Author:** ![YvetteLans](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yvettelans/32/6101_2.png) [@YvetteLans](https://community.fibery.io/u/YvetteLans)\
**Post date:** [March 18, 2023, 1:24pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/9 "2023-03-18T13:24:24Z")

</div>

> [@Chr1sG](#):
>
> Here’s a script that will append #mentions to linked items.  
> It can be triggered when an item is linked or unlinked, since it relies on clearing any previous #mentions and replacing them with the new needed ones.  
> It assumes that you have a many-to-many self-relation, with fields called ‘Parent’ and ‘Child’.  
> I hope it’s useful, or at the very least, inspirational.

Awesome 😍

> [@Matt\_Blais](#):
>
> Just wait until we get ChrisGPT-4 😁

If I look at the script, I think ChrisGPT has already been upgraded to version 4 🤣

---

<div class="post-metadata">

**Author:** ![Illusory](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/illusory/32/10403_2.png) [@Illusory](https://community.fibery.io/u/Illusory)\
**Post date:** [May 30, 2023, 12:31pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/10 "2023-05-30T12:31:19Z")

</div>

Hey @Chr1sG!

What is the best way to modify this so that we can mention “non-self-relations” (mention entities that are related via another database or app)

Furthermore, how can we modify non-relations entirely (entities from a completely unrelated database or app)?

Cheers,  
Josiah

---

<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:** [May 30, 2023, 12:40pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/11 "2023-05-30T12:40:39Z")

</div>

You would need to update a few lines, namely the ones that

- find the dbID for the entities you wish to mention (`const dbID = ...` )
- find the linked items (`const entityPlus = ...` )
- create the new list (`if ((entityPlus ...` onwards )

But out of curiosity, why do you want to add mentions for already linked items?

> [@Illusory](#):
>
> how can we modify non-relations entirely (entities from a completely unrelated database or app)?

What are you trying to achieve overall?

---

<div class="post-metadata">

**Author:** ![Illusory](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/illusory/32/10403_2.png) [@Illusory](https://community.fibery.io/u/Illusory)\
**Post date:** [May 30, 2023, 5:09pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/12 "2023-05-30T17:09:54Z")

</div>

We are more interested in mentioning entities that are not related via relation field and not within the same database or app.

We would like to create a button in a specified “event entity” to pull from our external database via script and reference/mention other entities within the rich text of that “event entity” based on our own conditions. Ideally, we can prepend the rich text field of the event entity.

So, being able to mention other entities via the script module would be helpful.

Example:

Let’s say I have an external database filled with Author quotes, from different authors.

I have App 1 with a database called “Authors”.

I created App 2 with a database called “Quotes”.

I want to create an entity in Quotes named “Inspirational”. Then, use a button to pull all quotes from my external database and if the quote in my external database is tagged as “inspiration”, I want to prepend the Rich Text field and mention the Author for reference within the “Inspirational” entity.

Then, within Author, I can see all the mentioned/referenced quotes within Inspirational.

---

<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:** [May 30, 2023, 8:02pm UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/13 "2023-05-30T20:02:18Z")

</div>

How is your external db linked into Fibery?

---

<div class="post-metadata">

**Author:** ![Illusory](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/illusory/32/10403_2.png) [@Illusory](https://community.fibery.io/u/Illusory)\
**Post date:** [May 31, 2023, 3:08am UTC](https://community.fibery.io/t/link-entity-in-rich-field-text/4138/14 "2023-05-31T03:08:48Z")

</div>

It isn’t! We would be pulling via http within the script. We’d love to create a custom app but don’t have the time to build.
