# Dashboard Context

The context is an optional feature found under the DashboardCustomize, and it is very important because it can holds a json object with many fields which can be used to build the component boards.

The json can either be a static json or a dynamic json built with handlebar (opens new window) code.

This example shows a context with a json that is build dynallically, and its output depends on the evaluation of the handlerbar's eq helper function.

# Example 1

{
"employees":[{name:"John",age:24},{name:"Doe",age:"35"}]
}

This example show a static json which contains one property named employees, which is an array of objects.

# Example 2:

{{#if (eq vars.query 3)}}
{
"name": "john doe",
"list": "id_goal_nível_3:{{vars.politic.id}}"
}
{{else if (not vars.query)}}
{
"name": "anonym",
"list": list("Workers","*", 100, 0, "age", "desc")
}
{{/if}}

# How to access the fields of the context json in the Boards

To access the fields of the json in the boards, all we need to do is invoke the name of the root property using the handlebars (opens new window) double curly brackets notations with its syntaxes. Example:

The result can be seen in the following image:

# Logging

{{log <ctx var>}}

Moreover, the user can also use the handlebars (opens new window) log functionallity to debug the json object on the console of the browser. by using the helper function log in the board, the user will see the contents of the variable employees on the console of the browser.

The result can be seen in the following image:

# Query Functions

In the second example we used a function called list. This function is used to perform an elesticsearch search based on the data given to its arguments, and the result is a list of objects. The following table shows the available similar funtions and their input arguments:

Context Query Functions:

Function Description arguments
list(definitionName, query, size, start, sort,ascending,options) returns a list of records from a definition definitionName:string,query:string, size:number, start:number, sort:string(sort field name), ascending="true OR false", options:{}
distinct(defName,fieldName,query,size,options) returns a list of distinct records from a definition defName:string,query:string, size:number, fieldName:string, options:{sort:string,ascending:"true OR false"}
httpGet(url,axiosConfig, options={}) returns the result of the get operation url:string,axiosConfig:object, options:object
httpPost(url, data, axiosConfig, options={}) returns the result of the post operation url:string, data:json , axiosConfig:object, options:object