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

Awesome :heart_eyes:

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