Link entity in rich field text

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:

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

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 :smiling_face_with_tear:

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

Thanks!

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

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

1 Like

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

2 Likes

BEEP BOOP :robot:

2 Likes

True story :rofl: ChrisGPT is way better than ChatGPT :grin:

1 Like

Just wait until we get ChrisGPT-4 :grin:

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.

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');
}

1 Like

Awesome :heart_eyes:

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

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

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?

What are you trying to achieve overall?

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.

How is your external db linked into Fibery?

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.