# Data Objects

Data Objects are the tables, views, methods, stored procedures, functions and custom SQL that you want to make accessible for reports.

All existing Data Objects are listed in the Main Menu under Data. All Data Objects that are added or edited will be displayed in a Tab entitled Objects.

- To add a new Data Object click ‘Objects’ in the Main Menu then click the 'Add' button.

> NOTE. Data Objects can be added quickly using Automatic Database Discovery.

- To edit a Data Object either double click it or select it and click the 'Edit' button.
- To delete a Data Object select it and click the 'Delete' button.
- To save changes click the 'OK' button or press the ‘Apply’ button.

Each Data Object has the following properties:

### Name

Select the Data Object’s Source from the first drop-down. In the second drop-down select a Data Object.

> NOTE. This will display all the of the Source’s tables, views, methods, stored procedures, and functions.

- To add custom SQL click the ‘Add Custom SQL’ button next to the Data Object drop-down. For more details see Custom SQL Objects.

> NOTE. The name of tables or views may not contain the following characters: { } (curly braces), [ ] (square brackets), ',' (comma), '.' (period/full stop), '%' (percent)

### Alias

The user friendly name for the Data Object. The alias will be displayed to end-users.

> NOTE. An alias may not contain the following characters: @ (at sign), { } (curly braces), [ ] (square brackets), ',' (comma), '.' (period/full stop), '%' (percent)

### Unique Key Fields

The columns which uniquely identify a row.

### Category

The ‘folder’ used to group related Data Objects. Sub-categories can be created by entering the category name followed by a backslash then the sub-category name.

> Ex. Sales\Clients

### Id

A unique value for the Data Object. Ids are required when creating multiple Data Objects with that have the same name but come from distinct Data Sources. Ids can also be used to optimize Web Service and .Net Assembly calls. For more information see Data Object Ids.

### Parameters

Parameters that are passed to stored procedures, table functions, Web Services or .NET assembly methods. Clicking in the drop-down will bring up a menu. Click the add button () and select the parameter from the drop-down list. For more information see Parameters, Stored Procedures and Web Services & .NET Assemblies.

- Parameter values are passed in the order in which they are listed in the Data Object. It is critical to ensure that the order is correct.

### Tenants Columns

Specify which columns contain tenant information and link the parameters accordingly.

- This setting is used to filter data when multiple users’ information is held within the same table or view and a column(s) holds information identifying each user. Exago will only retrieve the rows where the column value(s) matches the corresponding parameter(s).

### Column Metadata

Specify any columns that should not be filterable, visible, or that should be read as a specific data type. See Column Metadata for more information.

### Schema Access Type

Specify how Exago should retrieve the schema for the Data Object. There are three possibilities:

- Default – Follow the global Schema Access Type setting in Other Settings.
- Datasource – Queries the Data Source for the schema.
- Metadata – Reads the schema from the stored metadata.

> NOTE. For more information see Retrieving Data Object Schemas.

### Filter Dropdown Object

Specify an alternative Data Object to be queried when a user clicks the value drop-down in the Filters Menu. This setting is most likely to be used when the Data Object is a Stored Procedure, Web Service, or .Net Assembly that takes more than a few seconds to return data. In this scenario a table or view can be designated to increase performance.

> NOTE. The Filter Drop-down Object must have a column with the same name as each column in the main Data Objects.

### Suppress Sort and Filter

(v2018.1+) If this object is a programmable object (Stored Procedure or .NET Assembly Method), select whether to suppress the application sorting and filtering for report execution queries. Enable this if the programmable object uses Programmable Object Parameters to do sorting and filtering in code, and application processing would be redundant and unnecessary. This can allow for better performance for programmable objects.

> Note: If the application requires sorting/filtering in memory, it will not be suppressed - for instance, if a report with this object has a cross-source join, an advanced join, a Cartesian join, or a formula sort or filter. Multiple tables from the same PDO can be joined with suppressed filtering & sorting if this setting is enabled for all of them.

# Stored Procedures

Stored Procedures offer the ability to use high level code to modify the data set before it is sent to Exago.

Stored procedures must know what sorts and filters the user has set and whether to return the schema, a single column, or the entire data set.

To accomplish this:

- Use the Call Type, Filter, Column and Sort Parameters in the Programmable Object Settings. These parameters will be passed from Exago to identically named parameters in the Stored Procedure.
- Additional parameters may be passed by setting them in the Data Object Tab.

## Important Note for SQL Server:

SQL Server has an attribute called ‘FMTONLY’ that must be handled by all stored procedures.

'FMTONLY' has two possible values:

- ON: The stored procedure will only return the column schema. However all IF conditional statements are ignored and all of the code will be executed. This setting will fail if the stored procedure contains any temp tables.

- OFF: The stored procedure returns all of the data and the column schema. The stored procedure will correctly execute IF conditions.

The 'ON' setting will cause problems if there are IF conditions in the procedure; However, only using the 'OFF' setting will hurt performance if the Call Type Parameter in the Programmable Object Settings is not used.

The following example demonstrates how to use the Call Type, Column, Filter and Sort Parameters to maintain efficiency.

> NOTE. For SQL Servers, FMTONLY is set to OFF.

    ALTER PROCEDURE [dbo].[sp_webrpt_person]
    @callType INT, --optional but should be implemented for efficiency
    and dropdown support
    @columnStr varchar(1000), --optional; used for limiting data for efficiency
    @filterStr varchar (1000), --optional; used for limiting data for efficiency
    @fullFilterStr varchar (1000), --optional; used for limiting data for efficiency
    @sortStr varchar(1000) –-optional; may improve performance a bit if used
    AS
    SET NOCOUNT ON --for performance reasons
    SET FMTONLY OFF --force procedure to return data and process IF conditions

    declare @sql varchar(2000)
    declare @columnInfo varchar(1000)
    declare @orderbyClause varchar(1000)
    if @callType = 0 --return schema; don't need to return any rows
    begin
         set @sql = 'select * from vw_webrpt_person where 0 = 1'
    end
    else
    if @callType = 1 --return all data for execution
    begin
        set @orderbyClause = ''
        if @sortStr is not NULL AND @sortStr <> 'null' set @orderbyClause = ' ORDER BY ' + @sortStr
        set @sql = 'select' + @columnStr + ' from vw_webrpt_person where ' + @filterStr + @orderbyClause
    end
    else
    if @callType = 2 --return filter dropdown values; limit # rows to some value
    begin
         set @columnInfo = '[' + @columnStr + ']'
         set @sql = 'select top 100 ' + @columnInfo + ' from vw_webrpt_person where ' + @columnInfo + ' >= ' + @filterStr + ' and ' + @fullFilterStr + ' order by ' + @columnInfo
    end

    exec(@sql)

# Table Value Functions

Table Value Functions can be used as Data Objects. Any available table value functions of a Data Source will be displayed in the Data Object menu under Functions. Exago handles table value functions similar to views and tables except it will pass any parameters set in the Data Object Tab or in the Programmable Object Settings.

For more information, see Table-Valued Functions.

# Custom SQL Objects

Exago can use custom SQL as Data Objects. Parameters can be embedded in these SQL statements to enable you to change the statement at runtime.

To add or edit a Custom SQL Data Object click the ‘Custom SQL’ button and a dialog will appear.

### Data Object Name

The name of the Data Object to be displayed in the Administration Console.

### Data Source

The Data Source that will be sent the SQL.

### Parameter/Insert

Select the parameter you want to embed in the statements. Use the ‘Add’ button to move the selected parameter into the SQL statement where your cursor is located. Parameters may also be added manually between @ symbols (ex. @userId@).

Use the ‘TEST’ button to verify that the SQL statement is correct.

Press 'OK' to save the SQL statement or 'Cancel' to close the dialog without saving.

## Data Object Macros

‘Macros’ can be embedded in Custom SQL Data Objects to make them even more dynamic. Each macro allows for different SQL to be used according to the circumstances in which the Data Object is being called. Below are the details and examples of available macros.

### IfExecuteMode

(string trueCondition, string falseCondition)

Description | Will include the trueCondition if a user is executing a report. Will include the falseCondition otherwise.
Example | select * from vw_webrpt_optionee IfExecuteMode("where [State] = 'CT'","")

### IfExistReportDataObject

(string dataObjectName, string trueCondition, string falseCondition)

Description | Will include the trueCondition if dataObjectName exists inside the full Exago SQL statement to the data source. Will include the falseCondition otherwise.
Example | select * from vw_webrpt_optionee IfExistReportDataObject("fn_webrpt_grant", "join on fn_webrpt_grant...", "")

# Column Metadata

Column Metadata refers to the properties of each column in the Data Objects. Normally Exago gets the metadata for each column directly from the Data Source, however, in some cases it may be helpful to override or add additional information to the metadata.

To modify the metadata of a column, select it and click the ‘Add’ button or double click it. Enter a Column Alias or use the Data Type, Filterable, and Visible drop-downs to set the desired properties.

Click the ‘Read Schema’ button to quickly create column metadata for each column in the Data Object.

To remove Column Metadata for a column, select it in the right panel and click the 'Delete' button.

To save changes to Column Metadata, click the ‘OK’ button. Click the ‘Cancel’ button to discard changes.

The following properties of each column can be modified:

## Column Alias

The name of the Data Field that the end-users see.

## Column Description

(v2016.3+) Data fields can have description text added. If the data field is hovered over in a selection screen in the Report Designer, the description text will pop up:

Admins can add description text to data fields on an application-wide level. To do so, using the Admin Console, expand the Objects dropdown, and double-click on the desired data object, or select it and press Edit. Then, in the object menu click on the rectangle next to Column Metadata. This will open the Column Metadata dialog.

Double-click on the desired data field, or click-and-drag it to the Selected Columns pane, or select it and press the Add button. You have two options for adding description text: Using Plain Text or editing the Language File.

### Plain Text

Hovertext can be added verbatim in the Column Description field. In-line HTML tags like <b> can also be used if desired. Press OK when done, then Apply the change.

### Language File

You can also add description elements to the language file, and reference them in the Column Description field.

In the language file, add new elements to the <AdminObjects> section using the following format:

    <element id="uniqueIdentifier" tooltip="Description Text"></element>

HTML tags must be encoded like so:

- Encode < as &lt;
- Encode > as &gt;
- Encode " as &quot;

For example, the following tooltip string encodes "<b>Description</b> Text", which appears as "Description Text" in the hovertext.

    <element id="uniqueIdentifier" tooltip="&lt;b&gt;Description&lt;/b&gt; Text"></element>

After adding the element to the language file, add the id string to the Column Description field. Press OK when done, then Apply the change.

## Data Type

The type of data Exago should treat the Data Field as (ex. DateTime).

- Valid values for Data Type include: String, Date, Datetime, Time, Int, Decimal, Image, Float, Boolean, and Guid.

## Filterable

Whether this field can be used to filter reports. The available options are:

- All (True) - This field can be used as a report filter in the Advanced/Express/ExpressView Designers, Dashboard Designer, and Scheduler, and as an interactive filter in the Report Viewer.
- Dynamic (False) - This field can only be used as an interactive filter in the Report Viewer.
- Static (v2017.1.2+) - This field can only be used as a report filter in the Advanced/Express/ExpressView designers, Dashboard Designer, and Scheduler.
- None (v2017.1.2+) - This field cannot be used as either a report filter or interactive filter.

## Sortable

(v2016.3+) If set to 'False' the Data Field will not be listed in the Sorts menu.

Admins can now indicate whether data fields should appear in the Sorts menu using the Sortable dropdown.

> NOTE. This toggle does not prevent data fields from being sorted by. Users can still enter the data fields manually as a formula, or use the data fields within a sort formula.

## Visible

If set to 'False' the Data Field will not be listed for users.

### Sort and Group-By Value

(v2016.3+) Specify a custom formula by which columns should be sorted and grouped by the application.

This field allows admins to specify how columns should be sorted and grouped by the application. By default, Exago will sort (and group) columns based on the data in the column. You can use this metadata field to specify different data by which the column should be sorted.

For example, you may have a custom column Employees.FullName like the following:

{Employees.FirstName} & ' ' & {Employees.LastName}

By default, Exago would sort this field on the full string. You may want to sort on just the LastName, instead. In Sort and Group-By Value, enter {Employees.LastName}, and the column will sort on LastName.

Another common example is sorting a Month field by the numeric representation of the month instead of the name. Since this value accepts any valid Exago formula (except aggregates), custom functions can also be used.

> NOTE. The sort-and-group field must have a one-to-one relationship with the data field. Otherwise, unexpected behavior could occur.

## Custom Columns

(v2016.3+) Custom columns are a way to add columns to Exago that don't exist in the database. This is completely transparent for the users; they can then use them like any other column. New data fields can be created from composite or interpreted data fields. You could even use a formula to create data from scratch. Admins often use custom columns to make popular formula sorts available on an application-wide level.

### Admin Console

To add a custom column using the Admin Console, expand the Objects dropdown and double-click on the desired data object, or select it and press Edit. Then, in the object menu click on the rectangle next to Column Metadata. This will open the Column Metadata dialog.

Press the Add New button. Enter a name for your data field in the dialog box.

Data Type, Column Alias, and Column Value are required fields. In the Column Value field, press the formula button to bring up the Formula Editor.

Press OK when done, then Apply the change.

### Config File

To add a custom column by editing the config file, open the config file in a text or xml editor. Data objects are <entity> elements. Locate the entity and add a new <column_metadata> element:

    <entity>
      ...
        <column_metadata>
        <col_source>ExagoFormula</col_source>
        <col_name>FullName</col_name>
        <col_type>string</col_type>
        <col_alias>FullName</col_alias>
        <col_description>First and Last Name</col_description>
        <filterable>false</filterable>
        <col_value>{Employees_0.FirstName} &amp; ' ' &amp; {Employees_0.LastName}</col_value>
        <col_sortandgroupbyvalue>{Employees_0.LastName}</col_sortandgroupbyvalue>
      </column_metadata>
    </entity>

Bold fields are required.

<col_source>ExagoFormula</col_source> is static. This is the same for every <column_metadata>.

In <col_value> and <col_sortandgroupbyvalue>, data fields are identified by their id, not their alias.

Acceptable values for <col_type>: string, date, datetime, time, int, decimal, image, float, boolean, guid, currency

Save the config file when done, and restart the web server.

### Examples

There are a lot of options for what kinds of data fields you can create:

Transform or interpret an existing data field:

- Right({Employees.SocialSecurityNumber},4)
- Month({Orders.OrderDate})

Combine multiple data fields together:

- {Employees.FirstName} & ' ' & {Employees.LastName}

Create new data from scratch:

- Random(0,65536) (uses a custom function)

And much more!

> NOTE. Custom columns cannot be used as Filters, or inside Aggregate Formulas.

# Retrieving Data Object Schemas

Many of the dialogs throughout Exago require schema information (ex. column name, data type, etc.). By default these dialogs query the Data Sources for the schema. This process, however, may cause performance issues if the Data Sources take a considerable amount of time to return the schema.

To enhance performance, schema information can be stored as Column Metadata. Exago can then read the Column Metadata instead of querying the Data Source.

> NOTE. While storing the schema as Column Metadata improves performance, updates to the Column Metadata will be required whenever columns are added, removed, or retitled.

For Exago to retrieve schema information from Metadata:

1. In Other Settings, set ‘Schema Access Type’ to ‘Metadata’. This will force Exago to get all schema information from Metadata for all Data Objects.

> NOTE. Alternatively this setting can be overwritten for individual Data Objects by setting the ‘Schema Access Type’ property.

2. For each Data Object open the Column Metadata Menu.
   1. Click the ‘Read Schema’ button. A message will appear asking you to confirm you want to continue. Click 'OK'.
   2. Click 'OK' to close the Column Metadata Menu.
   3. Press 'Apply' or 'OK' to save the Data Objects.

> NOTE. Other metadata options such as aliasing can still be utilized.

# Data Object Ids

There are three ways in which you can utilize Data Object Ids.

### Adding Multiple Data Objects with the Same Name

Ids are used distinguish Data Objects that have the same name but come from different Data Sources. When adding multiple Data Objects with the same name, make sure each Data Object has a unique Id.

### Avoiding Issues from Changes to Object Names

Providing Ids for all the Data Objects will avoid issues if the name of the underlying tables, views, or stored procedures, is changed.

### Calling a Single Web Service/.Net Assembly/Stored Procedure

Web Services, .Net Assemblies, and Stored Procedures comprise a group called Programmable Data Objects. These Objects can retrieve parameters from Exago and the host application in order to control what data is exposed to the user.

Generally for Web Services and .Net Assemblies each Data Object calls a distinct method. Similarly each Stored Procedure is its own Data Object. By using Data Object Ids a single method/stored procedure can be called. This method can then return data or schema based on the Data Object Id.

To call a single Web Service/.Net Assembly/Stored Procedure:

- Provide a name for ‘Data Object ID Parameter Name’ in Programmable Object Settings
- Create a method/procedure in your Service/Assembly/Procedure that utilizes the Object Id Parameter to return the appropriate data/schema. (see example below)
- For each Data Object:
  - Select ‘Object’ in the Main Menu and click the ‘Add’ button
  - Select the single Service/Assembly/Procedure
  - Provide an Alias and an Id for the Object
  - Select the key columns
  - Click 'Apply' or 'OK' to save the Object.

Ex. This stored procedure uses the Object Id Parameter (@objectID) to return different data/schema information for different Object Ids.

    ALTER PROCEDURE "dbo"." Exago_Example"   @callType INT,  @objectID nvarchar(max)  AS
    SET
    NOCOUNT
       ON
    SET
    FMTONLY OFF    if @objectID = 'Produce'   begin      if @callType = 0      begin          SELECT
       ProductID,
       ProductName,
       SupplierID,
       UnitPrice,
       UnitsInStock
    FROM
       Products
    WHERE
       CategoryID = 1001
    end
    else if @callType = 1      begin          SELECT
       ProductID,
       ProductName,
       SupplierID,
       UnitPrice,
       UnitsInStock
    FROM
       Products
    ORDER BY
       ProductID
    end
    else if @callType = 2      begin          SELECT
       ProductID,
       ProductName,
       SupplierID,
       UnitPrice,
       UnitsInStock
    FROM
       Products
    ORDER BY
       ProductID
    end
    end  if @objectID = 'Orders0'   begin      if @callType = 0      begin          SELECT
    OrderID,
    OrderDate,
    RequiredDate,
    ShippedDate,
    CustomerID
    FROM
    Orders
    WHERE
    CustomerID = 0
    end
    else if @callType = 1      begin          SELECT
    OrderID,
    OrderDate,
    RequiredDate,
    ShippedDate,
    CustomerID
    FROM
    Orders
    ORDER BY
    OrderID
    end
    else if @callType = 2      begin          SELECT
    OrderID,
    OrderDate,
    RequiredDate,
    ShippedDate,
    CustomerID
    FROM
    Orders
    ORDER BY
    OrderID
    end
    end

# Reading Images from a Database

Exago can read images from a database and load them directly into a cell of a report. When images are stored in a database as a binary string there are two ways that Exago can load them into a report.

1. In the Administration Console edit the Data Object that contains the images. Open the Column Metadata Menu and for the image column set Data Type to ‘Image’. Next, simply place the Data Field containing the images into the desired cell of a report. Upon execution the images will be loaded into the cell.
2. Place the Data Field that contains the images into the LoadImage function. Upon execution Exago will interpret the binary and load the images into the cell.