Report samples
Basics
The table below shows how variables should be passed based on field type:
Field type | Type | Description |
---|---|---|
Date |
String |
Use the pattern yyyy-MM-dd (year-month-day) 2018-10-04 |
Select multiple |
String |
Use "," to separate each value "value1,value2,value3" |
Suggested code sample
First, you must create the web service object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);
Then you should log in using the method "login". You can access the "login" method from the web service object "ws" as shown below:
ws.login(user, password);
Once you are logged in with the web services, the session is kept in the web service object. Then you can use the other API methods
At this point you can use all the Report methods from "report" class as shown below:
ws.report.getReports(true)
Methods
getReports
Description:
Method | Return values | Description |
---|---|---|
getReports(boolean active) |
List<Report> |
Returns a list of reports. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
List<Report> reports = ws.report.getReports(true);
foreach (Report rep in reports)
{
System.Console.WriteLine(rep.toString());
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getReport
Description:
Method | Return values | Description |
---|---|---|
getReport(long rpId) |
Report |
Returns a report. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
List<Report> reports = ws.report.getReports(true);
Report report = new Report();
foreach (var rep in reports)
{
if (rep.fileName.Equals("DocumentCheckout.rep"))
{
// Get report
report = ws.report.getReport(rep.id);
break;
}
}
System.Console.WriteLine(report.toString());
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
executeReport
Description:
Method | Return values | Description |
---|---|---|
executeReport(long rpId, Dictionary<String, String> params, String format, String uuid) |
Stream |
Returns a document resulting from executing a report. |
Available formats:
The parameter uuid is the UUID of a node (this parameter is optional; it is usually used with reports executed from the user interface where the results of the reports depend on the selected node). |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.util;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
List<Report> reports = ws.report.getReports(true);
Report report = new Report();
foreach (var rep in reports)
{
if (rep.fileName.Equals("DocumentCheckout.rep"))
{
// Get report
report = ws.report.getReport(rep.id);
break;
}
}
Dictionary<String, String> param = new Dictionary<String, String>();
param.Add("from_date", "2016-01-01");
param.Add("to_date", "2016-12-23");
String uuid = "";
Stream stream = ws.report.executeReport(report.id, Report.FORMAT_PDF, param, uuid);
BeanHelper beanHelper = new BeanHelper();
Byte[] data = beanHelper.ReadToEnd(stream);
FileStream fileStream = new FileStream(@"C:\Desktop\out.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
foreach (byte b in data)
{
fileStream.WriteByte(b);
}
fileStream.Close();
} catch (Exception e) {
System.Console.WriteLine(e.ToString());
}
}
}
}
generateDownloadReportToken
Description:
Method | Return values | Description |
---|---|---|
generateDownloadReportToken(long rpId) |
String |
Returns the token for downloading the report. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8080/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
long repId = 1;
String dwt = ws.report.generateDownloadReportToken(repId);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}