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