Report samples
Basics
Section titled “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 split each value. “value1,value2,value3” |
Suggested code sample
Section titled “Suggested code sample”First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then you should log in using the method “login”. You can access the “login” method from the webservice object “ws” as shown below:
ws.login(user, password);At this point you can use all the Report methods from the “report” class as shown below:
ws.report.getReports(true)Methods
Section titled “Methods”getReports
Section titled “getReports”Description:
| Method | Return values | Description |
|---|---|---|
| getReports(boolean active) | List |
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
Section titled “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()); } } }}execute
Section titled “execute”Description:
| Method | Return values | Description |
|---|---|---|
| execute(long rpId, Dictionary<String, String> params, String format, String uuid) | Stream | Returns a document resulting from executing a report. |
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.execute(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()); } } }}executeSql
Section titled “executeSql”Description:
| Method | Return values | Description |
|---|---|---|
| executeSql(long rpId) | Stream | Returns a document resulting from executing a report SQL. |
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 rpdId = 1; Stream stream = ws.report.executeSql(rpdId); FileStream file = new FileStream("C:\\activity.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite); stream.CopyTo(file); file.Close(); stream.Close(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}getSqlReports
Section titled “getSqlReports”Description:
| Method | Return values | Description |
|---|---|---|
| getSqlReports(boolean active) | List |
Returns a list of SQL 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<SqlReport> sqlReports = ws.report.getSqlReports(true); foreach(SqlReport sqlr in sqlReports) { System.Console.WriteLine(sqlr.toString()); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}Description:
| Method | Return values | Description |
|---|---|---|
| save(long rpId, Dictionary<String, String> _params, String format, String dstId, String docName, String uuid) | Document | Executes the report and saves the resulting document. |
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; Dictionary<String, String> param = new Dictionary<String, String>(); param.Add("from_date", "2018-01-01"); param.Add("to_date", "2019-12-30"); String uuid = ""; Document doc = ws.report.save(repId, param, Report.FORMAT_PDF, "8599eab7-ae61-4628-8010-1103d6950c63", "REPORT-001.pdf", uuid); System.Console.WriteLine(doc.toString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}saveSql
Section titled “saveSql”Description:
| Method | Return values | Description | |
|---|---|---|---|
| saveSql(long rpId, Dictionary<String, String> _params, String dstId, String docName) | Document | Executes the report SQL and saves the resulting CSV document. |
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 rpId = 1; String dstId = 7f64d889-1600-4cbc-8134-ef6fb62287ec; String docName = "activity.csv"; Document document = ws.report.saveSql(rpId, new Dictionary<string, string>(), dstId, docName); System.Console.WriteLine(document.ToString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } }}generateDownloadReportToken
Section titled “generateDownloadReportToken”Description:
| Method | Return values | Description |
|---|---|---|
| generateDownloadReportToken(long rpId) | String | Return 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()); } } }}