Scroll

.NET Sample Code

To access the Exago Api, add a reference to the assembly WebReportsApi.dll to your project. 

In all of the examples below the return value should be checked for validity.  The examples below have omitted validations for clarity.

Create Api Object

// create WebReports API object passing Exago virtual path;

Api api = new Api("ExagoServer/Exago");

 

Adding/modifying a Role

// create a new runtime Role (is automatically made active)

Role role = api.Roles.NewRole();

// -- OR --

// accessing a pre-created Role and making it active

Role role = api.Roles.GetRole("Admin");
role.Activate();

 

Adding Folder security to role

// start with privileges to all folders for this user session (this is the default)

role.Security.Folders.IncludeAll = true;

 

// disallow access to folder 'Stew's Reports' (and any subfolders)

Folder folder = role.Security.Folders.NewFolder();

folder.Name = "Stew's Reports";

 

// make folder 'Summary Reports' (and any subfolders) read only

Folder folder = role.Security.Folders.NewFolder();

folder.Name = "Summary Reports";

folder.ReadOnly = true;

 

Adding Data Object security to role

 

// start with privileges to all data objects (this is the default)

role.Security.DataObjects.IncludeAll = true;

 

// disallow access to data object ‘vw_cancellation’

DataObject dataObject = role.Security.DataObjects.NewDataObject();

dataObject.Name = "vw_cancellation";

 

Adding Data Object Row security to role

 

// don’t allow this user to view rows from the ‘vw_grant’ object with a

// ‘Grant Date’ value of ‘2000-01-01’

DataObjectRow dataObjectRow = role.Security.DataObjectRows.NewDataObjectRow();

dataObjectRow.ObjectName = "vw_grant";

dataObjectRow.FilterString = @"""Grant Date"" <> '2000-01-01'";

 

Setting up several general user session parameters for role (overrides individual global general parameters)

 

// set global date format for this user

role.General.DateFormat = "dd/MM/yyyy";

 

// set currency symbol for this user

role.General.CurrencySymbol = "kr";

 

Modifying the data connection string of a specific data source

 

// set data connection string for a specific datasource

DataSource dataSource = api.DataSources.GetDataSource("MyDb");

dataSource.DataConnStr = "Server=SVR;Database=db1;uid=userId;pwd=password;";

 

Modifying a parameter value

 

// modify a parameter value

Parameter parameter = api.Parameters.GetParameter("asOfDate");

parameter.Value = "2007-06-01";

 

Setting a data column alias

 

// set column alias

api.Entities.GetEntity("vw_webrpt_optionee").ColumnMetadatas.SetColumnAlias("HIre Date", "Date of Hire");

 

Starting Exago - At this point if you want to run the Exago applications, do the following:

 

// setup URL

string url = "http://MyDomainServer/Exago/" + api.GetUrlParamString();

Response.Redirect(url);

 

// or you can redirect any control that can be set to a URL

this.ReportIFrame.Attributes["src"] = url;

 

Executing a report directly from the host application – You can combine setting user session information as above with report execution.  To do that, just omit the redirect above and do the following:

 

// load a specific report and return Report object (make sure to check return value)

Report report = (Report) api.ReportObjectFactory.LoadFromRepository(@"Stew Meyers' Reports\My Report");

 

 

// add a sort

Sort sort = report.Sorts.NewSort();

sort.DbName = "vw_optionee.First Name";

sort.Direction = wrSortDirection.Ascending;

report.Sorts.Add(sort);

 

// add a filter

Filter filter = report.Filters.NewFilter();

filter.DbName = "vw_grant.Grant Date";

filter.Operator = wrFilterOperator.LessThan;  // default is EqualTo

filter.Value = "20070501";  // filter dates are entered in YYYYMMDD sequence

filter.AndOrWithNext = wrFilterAndOrWithNext.And;  // default is And

filter.GroupWithNext = false;  // default is false

filter.Prompt = true; // default is false

 

// Set the Execute behavior to run in the Report Viewer (default is export to PDF)

report.ExportType = wrExportType.Html; // "Html" refers to the Report Viewer

 

// should Report viewer be opened in new browser window

report.OpenNewWindow = false;  // default is false

report.ShowStatus = false;  // default is true

 

// saves a temporary version of the report to be used for execution

api.ReportObjectFactory.SaveToApi(report);

 

Start report execution

 

// setup URL

string url = "http://MyDomainServer/Exago/" + api.GetUrlParamString();

Response.Redirect(url);

 

// or you can redirect any control that can be set to a URL

this.ReportIFrame.Attributes["src"] = url;

 

Executing a dashboard report directly from the host application:

api.Action = wrApiAction.ExecuteReport;

       DashboardReport report = Api.ReportObjectFactory.LoadFromRepository(@"Reports\My Dashboard") as DashboardReport;

              report.ReportItems[0].SetParameterValue("productname", "Parm1");

              report.ReportItems[0].SetFilterValue("Employees.EmployeeID", wrFilterOperator.EqualTo, new List<string>() { "3" });

              report.ReportItems[0].SetFilterValue("Orders.OrderDate", wrFilterOperator.GreaterThanOrEqualTo, new List<string>() { "1996-07-04 01:00:00" });

 

              report.ReportItems[1].SetParameterValue("productname", "Parm2");

              report.ReportItems[1].SetFilterValue("Employees.EmployeeID", wrFilterOperator.EqualTo, new List<string>() { "5" });

              report.ReportItems[1].SetFilterValue("Orders.OrderDate", wrFilterOperator.GreaterThanOrEqualTo, new List<string>() { "1996-07-04 01:00:00" });

 

              api.ReportObjectFactory.SaveToApi(report);

 

              string url = @"[Exago Install Path] /" + api.GetUrlParamString("Home");

        this.ReportIFrame.Attributes["src"] = url;

Scheduling a report with a filter and emailing results:

//load in the report

Report report = api.ReportObjectFactory.LoadFromRepository(@"Reports\Employee Performance") as Report;

 

//specify the export type of the scheduled report

report.ExportType = wrExportType.Pdf;

 

//set email information

List<string> toList = new List<string>();

toList.Add("emailaddress@example.com");

SchedulerEmailInfo info = new SchedulerEmailInfo(toList);

 

//set a filter on the report

Filter filter = report.Filters.NewFilter();

filter.DbName = "Employees.FirstName";

filter.Operator = wrFilterOperator.EqualTo;

filter.Value = "Janet";

filter.Prompt = true;

 

//create a schedule

api.ReportScheduler.CreateImmediateSchedule("Schedule Test", info);

 

//save the report to the api

api.ReportObjectFactory.SaveToApi(report);

 


Hidden Article Information

Article Author
Alex Agoado
created 2015-12-17 20:36:54 UTC
updated 2017-02-06 22:12:33 UTC

Labels
.NET, Examples,
Have more questions? Submit a request