# Reporting based on references

**URL:** <https://community.fibery.io/t/reporting-based-on-references/3777>\
**Category:** Get Help\
**Created:** [January 5, 2023, 11:25pm UTC](https://community.fibery.io/t/reporting-based-on-references/3777 "2023-01-05T23:25:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cannibalflea](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/cannibalflea/32/318_2.png) [@cannibalflea](https://community.fibery.io/u/cannibalflea)\
**Post date:** [January 5, 2023, 11:25pm UTC](https://community.fibery.io/t/reporting-based-on-references/3777/1 "2023-01-05T23:25:44Z")

</div>

I was wondering if there is any way of aggregating and reporting based on References/Back Links.

E.g. I have a set of initiatives which are discussed at various meetings. However, most of my meetings are not about initiatives, so in order to keep the number of explicit relations (and resulting mess in the front end) to a minimum, I have just been referring to these initiatives in my meeting entities with an inline reference. This way I can go back to the initiative entity and sort of get a list of meetings where it was referenced. However, at the moment, there doesn’t seem to be a way of categorizing back links (e.g. group them by the originating entity type) or generate any reports, like how many meeting we had where this initiative was discussed and how many hours does that represent.

I was wondering if this is somehow already possible.

---

<div class="post-metadata">

**Author:** ![cannibalflea](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/cannibalflea/32/318_2.png) [@cannibalflea](https://community.fibery.io/u/cannibalflea)\
**Post date:** [January 6, 2023, 7:24pm UTC](https://community.fibery.io/t/reporting-based-on-references/3777/2 "2023-01-06T19:24:50Z")

</div>

I was able to output the information through a script (currently just outputting into console but will write back to a markdown table) so that I can do the analysis in another tool. However, if there was a way of making better use of References in Fibery, that would be great 🙂

One of the things I noticed is that when there are multiple references in the same entity, then multiple instances come back. It would be great to be able to group my referring entity and the number of references.

```auto
// Script parameters
const PARENT_TYPE = 'Work Spaces/Initiative';
const REF_ENTITY_TYPES = ['Project Management/Project Meeting'];
const REF_ENTITY_FIELDS = ['Name', 'Date', 'Duration'];

// Fibery API is used to retrieve and update entities
const fibery = context.getService('fibery');

// Iterate through the entities
for (const entity of args.currentEntities) {
    const entityWithRefs = await fibery.getEntityById(entity.type, entity.id, ['References']);

    // Iterate through the references
    for (const ref of entityWithRefs['References']) {
        const refDoc = await fibery.getEntityById('Collaboration~Documents/Reference', ref['Id'], ['FromEntityId', 'FromEntityType']);
        const refType = refDoc['FromEntityType'].name;

        if (REF_ENTITY_TYPES.includes(refType)) {
            // Referring entity has a relation to the PARENT_TYPE
            const refEntity = await fibery.getEntityById(refType, refDoc['FromEntityId'], REF_ENTITY_FIELDS);
            if (refEntity != null) {
                var refEntityDate = new Date(refEntity['Date'].Start);
                console.debug(refEntity.Id + "," + refEntity['Name'] + "," + refEntityDate.toLocaleDateString("en-US") + "," + refEntity['Duration'] + ",");
            }
        }
    }
}

```

---

<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:** [January 20, 2023, 5:00pm UTC](https://community.fibery.io/t/reporting-based-on-references/3777/3 "2023-01-20T17:00:01Z")

</div>

> [@cannibalflea](#):
>
> However, at the moment, there doesn’t seem to be a way of categorizing back links (e.g. group them by the originating entity type) or generate any reports, like how many meeting we had where this initiative was discussed

This sort of thing is actually possible using a formula, but

> [@cannibalflea](#):
>
> how many hours does that represent.

is not really possible without scripting.

It boils down to the fact that refs are effectively polymorphic.  
You can filter by referring type and count them, but you can’t extract info (field values) from the referring entities.

---

<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:** [January 20, 2023, 5:01pm UTC](https://community.fibery.io/t/reporting-based-on-references/3777/4 "2023-01-20T17:01:39Z")

</div>

See here

> [@Using References in a formula](https://community.fibery.io/t/using-references-in-a-formula/905):
>
> Has anybody used References in a formula field? I’m experimenting to see if there’s any way I can create a field that returns all the items of a specific type that refer to the entity. For example, entity #1 of type A mentions entity #2, and entity #3 of type B also mentions entity #2. Can I write a formula for entity #2 that returns only those referring entities that are of type A (so it would only show entity #1)?
