# Custom integration: Define Lookup fields

**URL:** <https://community.fibery.io/t/custom-integration-define-lookup-fields/4455>\
**Category:** Get Help\
**Created:** [May 16, 2023, 11:31am UTC](https://community.fibery.io/t/custom-integration-define-lookup-fields/4455 "2023-05-16T11:31:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aoe](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/aoe/32/6018_2.png) [@aoe](https://community.fibery.io/u/aoe)\
**Post date:** [May 16, 2023, 11:31am UTC](https://community.fibery.io/t/custom-integration-define-lookup-fields/4455/1 "2023-05-16T11:31:50Z")

</div>

I have a custom integration with multiple databases. I have relations working correctly according to the documentation.

> **[Fibery Integration Apps API](https://api.fibery.io/apps.html#post-api-v1-synchronizer-schema)**
>
> The Fibery API provides a way to integrate Fibery with your external systems and automate routine tasks.

After databases, fields and relations are created, I have created a few simple Lookup fields to access more information.

Is it possible to define lookup fields in code? If so, where can I read more about it (I did not manage to find anything about _lookup_ in the documentation)?

---

<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:** [May 16, 2023, 11:44am UTC](https://community.fibery.io/t/custom-integration-define-lookup-fields/4455/2 "2023-05-16T11:44:02Z")

</div>

> [@aoe](#):
>
> Is it possible to define lookup fields in code?

Why do you want/need to use code to create the relation field?

---

<div class="post-metadata">

**Author:** ![aoe](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/aoe/32/6018_2.png) [@aoe](https://community.fibery.io/u/aoe)\
**Post date:** [May 16, 2023, 11:53am UTC](https://community.fibery.io/t/custom-integration-define-lookup-fields/4455/3 "2023-05-16T11:53:31Z")

</div>

I’ve had some problems with databases getting corrupt and have been forced to start from over again. And I’ve had to define the Lookup field again.

Having stuff defined in code feels better and I won’t forget the extra manual steps later 🙂

But let’s also say that I would like to have this custom integration as something to be shared with other people later on. It would be nice if the Lookup field is defined from the start (with code) and not something each individual user would have to setup.

Does that make sense? Or do you see another way of achieving the same thing?

I’m just curious if Lookup-relations can be defined in code since it can be defined in Fibery manually.

---

<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:** [May 16, 2023, 12:14pm UTC](https://community.fibery.io/t/custom-integration-define-lookup-fields/4455/4 "2023-05-16T12:14:12Z")

</div>

A lookup fields is basically the same as a formula field. Here is what one of my lookup fields looks like when I query the schema:

```auto
 {
    name: 'Demo/Lookup',
    id: '6fa1fb3f-bd70-49fe-b904-f4136f98f2b8',
    type: 'Demo/Database',
    rawMeta: {
      'ui/object-editor-order': 2,
      'formula/lookup?': true,
      'fibery/collection?': true,
      'fibery/field-reversed-collection?': true,
      'fibery/readonly?': true,
      'formula/formula?': true,
      'formula/formula': {
        expression: {
          'q/from': ['667ed2d8-594f-42ab-8f18-1594b03dbf99'],
          'q/select': {
            'fibery/id': {
              'q/from': ['eeec31e0-b1e9-482a-a422-b2fe888547ca'],
              'q/select': {
                'fibery/id': ['386c69d2-f00e-4241-9dc9-8dd1167664a5']
              },
              'q/limit': 'q/no-limit'
            }
          },
          'q/limit': 'q/no-limit'
        },
        params: {}
      },
      'history/disabled?': false
    },
    holderType: 'Demo/Task',
    isCollection: true,
    isTitle: false,
    isId: false,
    isPublicId: false,
    isReadOnly: true,
    isFormula: true,
    isFormulaDisabled: false,
    formulaDisableReason: null,
    formula: {
      expression: {
        'q/from': ['667ed2d8-594f-42ab-8f18-1594b03dbf99'],
        'q/select': {
          'fibery/id': {
            'q/from': ['eeec31e0-b1e9-482a-a422-b2fe888547ca'],
            'q/select': { 'fibery/id': ['386c69d2-f00e-4241-9dc9-8dd1167664a5'] },
            'q/limit': 'q/no-limit'
          }
        },
        'q/limit': 'q/no-limit'
      },
      params: {}
    },
    isLookup: true,
    hasLinkRule: false,
    linkRule: null,
    relation: null,
    defaultValue: null,
    objectEditorOrder: 2,
    isRequired: false,
    isHidden: false,
    isDeleted: false,
    disableLinkExistingItems: false,
    version: 1438,
    typeObject: [Getter],
    mixinTypeObject: [Getter],
    holderTypeObject: [Getter],
    nameParts: [Getter],
    title: [Getter]
  }

```

You _could_ potentially create a lookup field, using API calls and a bit of ‘reverse engineering thinking’ (we don’t have documentation, since it’s not really something we want to support).

However, the formula definition utilises the ids of existing fields/relations, so in your case, it is likely to be very challenging, since you would need to query the schema to find the correct ids, after the integration is created.

I might suggest as an alternative, that you create a relation field in your custom integration, and fill in the values based on a query that runs in the integration code.  
i.e. if you have these dbs: Project → Feature → Task and you want to lookup the Features’ Tasks in the Project db, just create a relation between Project and Task, and write the code in the integration to populate this with the correct values.

---

<div class="post-metadata">

**Author:** ![aoe](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/aoe/32/6018_2.png) [@aoe](https://community.fibery.io/u/aoe)\
**Post date:** [May 16, 2023, 12:59pm UTC](https://community.fibery.io/t/custom-integration-define-lookup-fields/4455/5 "2023-05-16T12:59:39Z")

</div>

Thanks, I’ll do that.
