Skip to main content

JSON Relations

Relations are used to get access to fields from other modules. This is useful when you want to display data from another module in a widget. Relations are defined in the relations object.

JSON Configuration

PropertyTypeRequiredOptionsDescription
parentintegerYesN/AThe ID of the parent module in the relation.
childintegerYesN/AThe ID of the child module in the relation.
relationidintegerYesN/AThe ID of the specific relation, if multiple relations exist between the two modules.
relationtypestringNochild/parentThe type of relation, typically defined automatically.
parent_idintegerNoN/AForcefully set the parent item of the relation. Normally you should never use this.
child_idintegerNoN/AForcefully set the child item of the relation. Normally you should never use this.

Naming of each relation object

The naming of a relation object is crucial as it determines how the relation is accessed. The name should correspond to the module ID from which you want to fetch information. For example, if you are working with Module 1 and need to fetch data from Module 2, you should name the relation object module2.

Examples

Example 1: Simple relation example

{
"relations": {
"module43": {
"parent": 43,
"child": 41,
"relationid": 22
}
}
}

In this relation configuration, the parent module is identified as module 43, and the child module as module 41. The relationid is set to 22, indicating the specific relation used if multiple relations exist between these two modules.

Example 2: Get relation's relation

{
"relations": {
"module77": {
"parent": 77,
"child": 123,
"relationid": 133
},
"module75": {
"parent": 75,
"child": 77,
"relationid": 79,
"child_id": "module77Item.id"
}
}
}

Example 3: Get Relations relation

In this scenario we have the following modules and relations.

Module IdName
33Lokation
34Udstyr
35Booking

When an Udstyr is Booked, a relation is created between Udstyr->Booking and between Lokation->Booking

Relation IdParent ModuleChild Module
2134 Udstyr35 Booking
2233 Sag35 Booking

We would like to show a table, displaying all Booked udstyr with their booking details and the name of the lokation.

To do this, we need to:

From Udstyr, get the booking

{
"module35": {
"parent": 34,
"child": 35,
"relationid": 21
}
}

From Booking, we need to get Lokation (as there are no relation between Udstyr and Lokation) What is speciel here, is that we are able to define what item this relation should depend on eg. by using “child_id”. Here we specify that it should use module35 child id (item).

{
"module33": {
"parent": 33,
"child": 35,
"relationid": 22,
"child_id": "module35.child_id"
}
}

Now we are able to get the both direct relations and related relations.

Example 4: Filter on a parent relation.

In this case we want to get all product use lines on all tasks related to the project user is currently vieweing.

Module IdName
168Project
169Task
171Product Use
172Product

Our relations looks like the followingen:

Relation IdParent ModuleChild Module
195168 Project169 Task
197169 Task171 Product Use
199172 Product171 Product Use

Our json looks like this:

{
"moduleid": 171,
"relations": {
"module169": {
"parent": 169,
"child": 171,
"relationid": 197
},
"module168": {
"parent": 168,
"child": 169,
"relationid": 195,
"child_id": "module169Item.id"
},
"module172": {
"parent": 172,
"child": 171,
"relationid": 199
}
},
"query": [
[
"module168Item.id",
"=",
"[itemid]"
]
],
}

To explain this:

  1. This is a table widget on the Project (meaning our [itemid] is the project id).
  2. Fetch data from Product Use (moduleid 171)
  3. Get the task related to the product use (in order to know which project it belongs to). "module169": {
  4. Get the project related to the task "module168": {
  5. Filter on the project id "query": [ ["module168Item.id", "=", "[itemid]"] ]
  6. Get the product related to the product use "module172": {
  7. The query will now return all product use lines on all tasks related to the project user is currently viewing.