# Automatic linking of inline Entities

**URL:** <https://community.fibery.io/t/automatic-linking-of-inline-entities/4968>\
**Category:** Get Help\
**Created:** [August 17, 2023, 11:39am UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968 "2023-08-17T11:39:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dukevannori](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dukevannori](https://community.fibery.io/u/dukevannori)\
**Post date:** [August 17, 2023, 11:39am UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968/1 "2023-08-17T11:39:53Z")

</div>

Is there a way of automatically link entities from inside a rich text field to the corresponding entity?

for example: If i mention a “task” in a Description field of a meeting, can that be automatically added to the “task” list relation of that meeting?

---

<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:** [August 17, 2023, 3:59pm UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968/2 "2023-08-17T15:59:12Z")

</div>

That would require some scripting, but unfortunately there is no Automation trigger for “Entity Reference added in Rich Text” 😕

You would either need to run it off a manually-clicked Button, or a timer-driven Rule (which can only run max once/hour).

A script could extract entity references from a Rich Text field and link the entities to a collection.

---

<div class="post-metadata">

**Author:** ![dukevannori](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dukevannori](https://community.fibery.io/u/dukevannori)\
**Post date:** [August 17, 2023, 6:10pm UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968/3 "2023-08-17T18:10:08Z")

</div>

awesome. thats good news.

would that be something that is easily done or does it require some javascript magic? is there e reference somewhere in the docs?  
thanks!

---

<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:** [August 17, 2023, 7:51pm UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968/4 "2023-08-17T19:51:58Z")

</div>

Definitely would require some javascript magic 🧙‍♂️  
Docs are here: [. | Fibery](https://the.fibery.io/@public/User_Guide/Start-6568#Guide/Scripts-54)

Here’s a Button script that scans through a Rich Text to find all references to Users.  
Note that there is a bunch of additional code that’s not related to your specific needs.

```auto
// Create Call Log (and Call Log Entries) from Attendees info in entity Description

const CALL_LOG_TYPE = 'Users/Call Log'
const CALL_LOG_ENTRY_TYPE = 'Users/Call Log Entry'
const ENTRIES_FIELD = 'Call Log'
const CLIENTS_FIELD = 'Clients'

const fibery = context.getService('fibery')
const assert = (condition, msg) => { if(!condition) throw new Error(msg) }

for (const entity of args.currentEntities) {
    const client = entity['Client']
    const descriptionSecret = entity['Description'].Secret
    const content = await fibery.getDocumentContent(descriptionSecret, 'md')
    const text = find_H_content(2, content, 'ATTENDANCE')
    const users = text.match( /(?<=\[\[#@)[0-9a-f/-]{70,}.*/g )
    //console.log('UserIds: ' + users.join('\n'));
    const mtgDate = findTopH1MtgDate(content)

    // Create the Call Log
    const callLog = await fibery.createEntity(CALL_LOG_TYPE, {
        'Meeting Notes': entity.Id,
        'Date': mtgDate,
        'Name': client.Name + ' - ' + mtgDate
    })
    await fibery.addCollectionItem(CALL_LOG_TYPE, callLog.Id, CLIENTS_FIELD, client.Id)

    // Create and link a Call Log Entry for each attendee user
    for (const u of users) {
        const m = u.match( /^([0-9a-f/-]{70,})\s*(.*)/ )
        if( !m ) continue
        const uid = m[1].replace( /^.+?\//, '' ) // remove Type Id
        let status = null // default status
        if (m[2]) {
            status = m[2].match( /\by|[✅☑✔]/i ) ? 'Attended' :
                m[2].match( /\bn|[❌✖❎]/i ) ? 'No-Show' :
                m[2].match( /\bc/i ) ? 'Canceled' :
                null
        }
        const fields = { 'Call Log': callLog.Id, 'User': uid }
        if(status) fields['Status'] = status
        const entry = await fibery.createEntity(CALL_LOG_ENTRY_TYPE, fields)
    }
}

// Find and return the text content of the named H-section (level=2 means H2, etc)
function find_H_content(level, content, title) {
    const regex = new RegExp(`^#{${level}}[^#]\\s*\\W*\\s*${title}([\\s\\S]*?)\\n#{1,${level}}[^#]`, "ims")
    const m = content.match(regex)
    assert( m, `Did not find "${title}" H${level} section` )
    return m[1]
}

function findTopH1MtgDate(content) {
    try {
        const d = content.match(/^# (.*MEETING.*)/i)[1]
            .match(/(\d+[-\/.]\d+[-\/.]\d+)/)[1]
        return new Date(d).toISOString().substr(0,10)
    } catch (err) {
        throw new Error('Could not find Meeting H1 with Date in Meeting Notes')
    }
}

```

---

<div class="post-metadata">

**Author:** ![dukevannori](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dukevannori](https://community.fibery.io/u/dukevannori)\
**Post date:** [August 17, 2023, 8:09pm UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968/5 "2023-08-17T20:09:33Z")

</div>

wow, thanks - will look through this tomorrow.

---

<div class="post-metadata">

**Author:** ![Yuri\_BC](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/yuri_bc/32/8803_2.png) [@Yuri\_BC](https://community.fibery.io/u/Yuri_BC)\
**Post date:** [August 18, 2023, 5:41pm UTC](https://community.fibery.io/t/automatic-linking-of-inline-entities/4968/6 "2023-08-18T17:41:43Z")

</div>

Related, and probably the solution:

> [@References reloaded](https://community.fibery.io/t/references-reloaded/4879):
>
> We are working on a new version of the Reference feature as part of our [H2 plans](https://community.fibery.io/t/fibery-roadmap-for-july-dec-2023-previous-roadmap-reflection/4690/33). We know this feature is complex, but we strongly believe it will add much value to Fibery. Here’s what we have in store for you with the new Reference feature: Better Integration: Our goal is seamlessly integrating references into Fibery as a first-class entity. This will make references feel like a more natural and integrated part of the platform. Easy and Powerful Linking: With the new version, you can connect…
