Skip to main content

 

This article will explain how you can build a relationship between different entities in Gen 2. Out-of-the-box you can have relationship between the same entities - e.g. Catalog Items. But what if you would like to define a relation between different entities? E.g. Source and Report (custom entity)? Following are steps that will explain how to do it.

 

Assumptions

You have your two entities between which you would like to have a relationship. For this article we will use source (default entitiy) and report (custom).

 

Create the relationship entity

First, go to the Global Settings (or Organization) → Metadata Model and create a new entity that will store the relationships. Name it e.g. sourceReportRelationship. It will have following properties:

  • order (Integer)
  • source (Referenced Object: source)
  • target (Referenced Object: report)
  • type (Referenced Object: relationshipType).

 

Put the new relationship entity in metadata entity

Under Metadata model, navigate to the entity metadata. Add a new property of type Embedded Object Array and choose our new entity sourceReportRelationship. Name the new property sourceReportRelationships.

Now run the changes. In version older than 13.4 go to the Metadata Model and click on Publish and Restart, in version 13.5+ go to the Upgrade Center and click on Run changes to run the changes. Do a DB backup if needed.

Add the relationship widget to the FE layout

After the restart, navigate to the sources, open one source and then open the Screen Layout screen (you can use the Ctrl + Alt + T shortcut). Insert following widget in the JSON (place it to the position of your choice):

{
"_type": "relationships",
"relationshipPropertyPath": "/sourceReportRelationships",
}

Press Ctrl + S to save the changes. The widget should appear on the screen: 

You can do the same for the aother entity (reports) to see the relationship from both sides.

Extra tip

You can have multiple relationship widgets on the screen with different entities. To distinguish between them it may be handy to rename the widget. As of version 13.8 it is not possible, but you can wrap the widget into a Card widget like this:

{
"_type": "entity.card",
"title": "Relation to Reports",
"hideWhenNoProperties": false,
"children": >
{
"_type": "relationships",
"relationshipPropertyPath": "/sourceReportRelationships",
}
]
}

The property "hideWhenNoProperties": false makes the Card widget to appear when there are no real properties inside.

The result looks like this:

Resources

Working with Metadata Model documentation

 

Be the first to reply!

Reply