Insert entity reference with scripts or markdown templates

I am wondering if there is currently a way of inserting entity references in rich text areas via scripts or through markdown templates.

The help page on markdown templates seems to show only inserting some attributes as simple text. I thought that using inline javascript might help but I couldn’t find a way of constructing an inline reference and appending it to the rich text field.

A #mention to an entity is constructed in a Fibery-markdown compatible form as follows:
where xxxxxx is the ID of the database and yyyyyy is the ID of the entity.

You can use scripting to determine xxxxxx and yyyyyy.

I hope that you already know how to get yyyyyy.

For the database ID, you’ll probably need something like this:

const fibery = context.getService(‘fibery’);
const schema = await fibery.getSchema();
const dbID = schema[‘typeObjects’].filter((obj) => == ‘spacename/dbname’)[0][‘id’];

I hope this makes sense, and is informative enough to allow you to experiment and achieve what you want to do.