# How to create an auto-linked entity in Rule?

**URL:** <https://community.fibery.io/t/how-to-create-an-auto-linked-entity-in-rule/2984>\
**Category:** Get Help\
**Tags:** automations\
**Created:** [June 20, 2022, 5:20pm UTC](https://community.fibery.io/t/how-to-create-an-auto-linked-entity-in-rule/2984 "2022-06-20T17:20:36Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [June 20, 2022, 5:20pm UTC](https://community.fibery.io/t/how-to-create-an-auto-linked-entity-in-rule/2984/1 "2022-06-20T17:20:36Z")

</div>

With “normal” relations (i.e. not auto-linked), I can use the “Add new entity” Action to create and link a new entity in a Rule.

But when I change the relation to Automatically Link, that Action is no longer available.

Is there no way (besides script) to create a new related (auto-linked) entity?

---

<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:** [May 23, 2023, 8:06pm UTC](https://community.fibery.io/t/how-to-create-an-auto-linked-entity-in-rule/2984/2 "2023-05-23T20:06:04Z")

</div>

**For reference - this is how I solve the problem of creating auto-linked entities “on demand”.**

In this example, the main DB is `Contacts`, and every `Contacts` entity should be auto-linked to a `Meta Contacts` entity sharing the same Name (there can be multiple `Contacts` entities with the same Name, and these all get linked to one `Meta Contact` entity).

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/b/b262fb71b8c8706312ff4fd6034d78cffae4718e.png)

The question is, how to automatically create new `Meta Contacts` entities when needed, so they can be auto-linked to matching `Contacts` entities? That is done by this `Contacts` rule:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/2/22bd6181da9a0622ffcccc6ca5eae5d92391110e.png)

```auto
//------------------------------------------------------------------------------------------------
// DB: Contacts
// RULE: Create Meta Contact
// WHEN: Contacts Created, or Contacts Updated (Update, Name)
// ASSUMPTIONS:
// Contacts has many-to-one relation 'Meta Contacts', which is auto-linked on Name = Name
//
// Create the associated Meta Contact (which will be auto-linked on the Name field)

const fibery = context.getService('fibery')

const THIS_TYPE = args.currentEntities[0].Type
const SPACE = THIS_TYPE.replace(/\/.*/, '')
const OTHER_TYPE = SPACE + '/Meta Contacts' // Other DB
const OTHER_FIELD = 'Name' // Auto-Linking field in other DB
const LINK_FIELD = 'Name' // Auto-Linking field in this DB
for (const entity of args.currentEntities) {
    await fibery.createEntity(OTHER_TYPE, { [OTHER_FIELD]: entity[LINK_FIELD] })
}

```

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 20, 2025, 5:25pm UTC](https://community.fibery.io/t/how-to-create-an-auto-linked-entity-in-rule/2984/3 "2025-02-20T17:25:20Z")

</div>


