Skip to main content

INTRO

Sometimes you need to enrich your entity view with the combination of attribute values or attributes that belong to some other entity… and there is a way to do it using computed content feature.

Following are the two use cases I happen to encounter most often.

 

Show parent attribute in a child entity

  • You have report and reportColumn entities.
  • Entity reportColumn is an array of embedded objects inside report.
  • Entity report has a reportName attribute.

The goal is to add report.reportName to reportColumn entity as reportName attribute.

 

High level steps:

  1. Create a new entity named reportNameCC, save it, **DO NOT PUBLISH**.
  2. In the Computed Content tab of the entity add parameters and SQL.
  3. Edit reportColumn entity
    1.  add embedded object with type reportNameCC;
    2.  add delegate property to embedded reportNameCC.

 

Computed Content Entity

  1. Goto Organization → Metadata Model
  2. Press Create entity and create empty reportNameCC entity.
  3. Save but **DO NOT PUBLISH!**
  4. Open Computed Content tab and fill in:
    • Input Attributes -- entities that are participating in the computation.
    • Query -- templated SQL query that does computation.
    • Computed Properties -- output properties to be used when this computed content entity would be embedded.


Input Attributes

Add 2 entities: report and reportColumn. Both should have required properties added too:

Aliases and names would be used in the query.


Query

Templated SQL query is not very user friendly but it gets the job done.

We want to have SQL that for every report extracts all report columns and adds reportName to them:

  select
c.$cId$ as "id_i",
c.$cId$ as "parent_id_i",
r.$rFrom$ as "from_h",
$path(c.$cPath$)$ as "path_i",
$type()$ as "type_i",
r.$rName$ as "reportName" -- (1)
from $r$ r
inner join $c$ c on r.$rId$ = c.$cParentId$


(1) Should be used as an output in Computed Properties


Computed Properties

We should add computed property and it is just a mapping to SQL column defined in SQL query above:


Now press Preview result to check if there is a data:


And if it is there publish the changes.


Apply Computed Content Column

  1. Goto Organization → Metadata Model.
  2. Find and edit reportColumn entity.
  3. Press Add property and add property as Embedded object with type reportNameCC:

     

  4. Press Add property and add another property as Delegated scalar property, set Via property to previously added computed content property reportNameCC, set Delegate property to reportName:

     

  5. Publish changes.


Now there is an "issue": I can see 2 report names when I open the report column:

 

We can hide computed column embedded property with layout change:

  1. Open web browser console (Ctrl + Shift + I in most browsers)
  2. Execute OpenDebuggingTools() javascript function (Or you can press :Ctrl + Shift + T):

     

  3. We can blacklist a property to hide it from this layout view. Edit the layout:
    {
    "_type": "entity.controller",
    "children": {
    "_type": "entity.page.detail",
    "showViolations": true,
    "children": {
    "_type": "grid",
    "items":
    {
    "cols": 14,
    "children": {
    "_type": "entity.entity",
    "children":
    {
    "_type": "entity.property",
    "name": "description"
    },
    {
    "_type": "entity.card",
    "title": "General information",
    "children": {
    "_type": "entity.property.rest",
    "propertyTypes": r"S", "SRE"]
    }
    },
    {
    "_type": "entity.property.rest",
    "propertyTypes": r"SEE", "AEE"],
    "blacklist": "reportNameCC"]
    }
    ]
    }
    }
    ]
    }
    }
    }

    Where reportNameCC is a blacklisted property.

  4. Press CTRL + S (or CMD + S on OSX) to save the layout.


The result is:


Unfortunately, there is no way to hide it from the right panel view:

 


Concatenate Attribute Values

  • You have report entity.
  • It has reportName, year and type string properties.

The goal is to add reportFullName property to report which is a concatenation of type + reportName + year.

 


Computed Content Entity

  1. Goto Organization → Metadata Model
  2. Press Create entity and create empty reportNameCC entity.
  3. Save but **DO NOT PUBLISH!**
  4. Open Computed Content tab and fill in:
    • Input Attributes -- entities that are participating in the computation.
    • Query -- templated SQL query that does computation.
    • Computed Properties -- output properties to be used when this computed content entity would be embedded.


Input Attributes

Add entity: report with required properties + properties that we would like to use for concatenation:


Aliases and names would be used in the query.


Query
 

SQL should just select everything and concatenate rType, rName and rYear:

.. code:: sql

  select
r.$rId$ as "id_i",
r.$rId$ as "parent_id_i",
r.$rFrom$ as "from_h",
$path(r.$rPath$)$ as "path_i",
$type()$ as "type_i",
r.$rType$ || ' ' || r.$rName$ || ' ' || r.$rYear$ as "fullName" -- (1)
from $r$ r

(1) Should be used as an output in Computed Properties


Computed Properties

We should add computed property and it is just a mapping to SQL column defined in SQL query above:


Now press Preview result to check if there is a data:


And if it is there,  publish the changes.


Apply Computed Content Column

  1. Goto Organization → Metadata Model
  2. Find and edit report entity.
  3. Press Add property and add property as Embedded object with type reportFullNameCC

     

  4. Press Add property and add another property as Delegated scalar property, set Via property to previously added computed content property reportFullNameCC, set Delegate property to fullName:  

     

  5. Publish.

 

 

 


What if you would like to concatenate reference attribute?

Now imagine that instead of plain string there is an attribute with dropdown values -- brand -- and you want to add its value to the concatenation.

 

  1. Goto Organization → Metadata Model
  2. Find and open reportFullNameCC entity.
  3. Goto Computed Content tab and add another input entity Brand

     

  4. Change the Query to 
     
    select
    r.$rId$ as "id_i",
    r.$rId$ as "parent_id_i",
    r.$rFrom$ as "from_h",
    $path(r.$rPath$)$ as "path_i",
    $type()$ as "type_i",
    b.$bName$ || ' ' || r.$rType$ || ' ' || r.$rName$ || ' ' || r.$rYear$ as "fullName" -- (1)
    from $r$ r
    left join $b$ b on b.$bId$ = r."brand_ri" -- (2)


    (1) Here b.$bName$ is added. Value from the joined Brand entity.
    (2) Join condition is a simple one (although not obvious). You have to join referenced entity (Brand) by its Id with the main entity (Report) by the reference id brand_ri. It would always be name of the reference attribute + _ri.

  5. Publish

 

 

OUTRO

That is it, not the easiest implementation one can wish for, but it gets the job done. 🤘🏽 

Be the first to reply!

Reply