Add a custom field in an insight

Learn how to add a custom field in an insight

Neli Ivanova avatar
Written by Neli Ivanova
Updated over a week ago

In many organizations there are additional fields that add value when analyzing OKRs. Custom fields on Objectives, Key Results, Tasks, etc. allow that additional information to be captured. That information is available to be used in insights as well.

These steps assume you have already created a custom field. The examples below are for objectives specifically, but will work for other object types as well.

Retrieve the Custom Field Key

To use the custom field in an insight, you will need the custom field key. This can be retrieved under Settings > Custom Fields, look for the "Unique Key" column. If the "Unique Key" column is not displayed, click "Columns" and display it.

Adding Simple Custom Fields to Insights

The example below assumes you are using a "simple" custom field that is not a multi-select. See below for how to work with multi-select fields.

Note: If you are using the Offline Insight Editor, there are snippets you can use to support working with custom fields.

Add to the insight SQL

In the insight editor, add the following to your SQL's select statement:

CASE WHEN g.customfields <> ''
THEN (g.customfields::json ->> 'ah_contribu')
ELSE ''
END AS contributor
  • This assumes you have aliased the quantiveresultsgoals table to g

  • In this example, the unique key is "ah_contribu".

Add to the HTML

This example assumes that your data is displayed in a HTML table. If your data is displayed in another way (using divs, for example) then you will need to adjust your code accordingly.

Add a table header:

<th>Contributor</th>

Add a cell to the repeated table row block

<td>{{goal.contributor}}</td>

This assumes that your ng-repeat directive that creates the table rows looks something like this:

<tr ng-repeat="goal in objectives | orderBy : orderKey : reverse">

Adding Multi-Select Custom Fields to Insights

For Multi-select list or User/Team selector custom fields, you will need to adjust the code to display properly. The code below is one example that will display each distinct value in its own line. There are many other possibilities depending on your display needs.

Add the field in the insight SQL

We must translate the custom field value into a PostgreSQL array format, We can do that using this code:

(CASE WHEN g.customfields <> ''
THEN REPLACE(REPLACE(g.customfields::json ->> 'ib_category','[','{'),']','}')
ELSE null
END)::text[] AS category
  • This assumes you have aliased quantiveresultsgoals to g

  • This assumes the custom field key is "ib_category"

This will convert the JSON array stored in the customfields property "ib_category" to a PostgreSQL array and will be null if the customfields or ib_category properties are blank.

Add the field in HTML

This example assumes that your data is displayed in a HTML table. If your data is displayed in another way (using divs, for example) then you will need to adjust your code accordingly.

Add a table header:

<th>Category</th>

Add a cell to the repeated table row block

<td>
<div ng-repeat="category in goal.category">
{{category}}
</div>
</td>

If you are using a User/Team selector, use the Assignee component to display the assignee (otherwise you will just see the ID of the user or team)

<td>
<div ng-repeat="contributor in goal.contributors">
<assignee id="{{contributor}}"></assignee>
</div>
</td>

This assumes that your ng-repeat directive that creates the table rows looks something like this:

<tr ng-repeat="goal in objectives | orderBy : orderKey : reverse">
Did this answer your question?