Make "creation context" available to scripts

Scenario: I am typing notes in the richtext Description field of a “Meeting Notes” entity.

When I create a new Task entity inline (via Ctrl+E), and I want a script to automatically set some fields in the new Task entity upon creation, and it has existing relations that are relevant.

But the script needs to know the context in which this new Task entity is created – i.e., this “Meeting Notes” entity is a kind of “parent context” for its creation.

The script needs this parent-context to get the related “Project” for the new Task entity (e.g. the Project relation in the “Meeting Notes” entity).

I don’t know how useful it is for your scenario, but it is possible to find stuff out about the items that are referring to an entity.

There is a (hidden) field called ‘References’ which is a collection of entities of the ‘Collaboration~Documents/Reference’ type. Each Reference entity contains all the useful info about the reference, including the ID of the referring entity.

Here’s an example of how you can access the ID of the first reference in the collection and thereby get the ID of the referring entity:

const entityWithExtraFields = await fibery.getEntityById(entity.type, entity.id, ['References']);
const firstRefID = entityWithExtraFields['References'][0]['Id']
const refWithDetails = await fibery.getEntityById('Collaboration~Documents/Reference', firstRefID, ['FromEntityId'])

You can probably figure out some of the rest yourself, but to give you a steer in the right direction, here’s a idea of the fields that the ‘Collaboration~Documents/Reference’ type contains:

image

I could imagine for your use case, you would want to find the most recently created reference, then find the FromEntityID…

Feel free to let us know how you get on :slight_smile:

@Chr1sG, yes that’s useful for the example I described above, where we know there will be a reference in a specific field.

But in other cases this would not work; i.e. if we are creating an entity within a table view’s relation cell. In this case a script could still benefit from knowing the context/parent for the object creation. Or would such a reference field be automatically set?