A First Program
Having installed Data Abstract for JavaScript, we are going to create a short script that will access one of the sample databases that comes pre-installed with Relativity server. We will break the script down into multiple sections and explain what is going on at each step.
You may wish to open a browser tab on the Data Abstract for JavaScript API as you work through this page so that you can see a breakdown of the objects and methods available to you.
Step 1
The first step is create an index.html
file somewhere in your filesystem. This will be the only file you will need for this example, though normally you might refer the Data Abstract JavaScript libraries on the local file system.
Into the file, start by adding the following basic framework. The script references are pointing to compressed versions of the JavaScript libraries that come with Data Abstract for JavaScript, but are served here by the instance of Relativity server that we will be using.
The RemObjectsSDK.js
is a JavaScript based version of the Remoting SDK which is the foundation for the implementation of Data Abstract. The DataAbstract.js
file implements the Data Abstract services and provides the support for accessing both the Relativity server or a custom Data Abstract server. Lastly the DataAbstract4_intf.js
file is generated from a DataAbstract.rodl
and works in conjunction with the RemObjectsSDK.js
to interact with the server.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://localhost:7099/js/RemObjectsSDK.js" type="text/javascript"></script>
<script src="http://localhost:7099/js/DataAbstract.js" type="text/javascript"></script>
<script src="http://localhost:7099/js/DataAbstract4_intf.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
Remember that the libraries provided with Data Abstract for JavaScript come in both compressed and uncompressed form so that you can examine what they are doing.
Step 2
In the <body></body>
section add the code below. It defines a table with an id
of depsTable
, which will be referenced later in Step 4, and provides a bit of styling to the HTML table that will be generated by. Both da_htmlTableHeader
and da_htmlTableLine
are available to you for applying CSS styling.
<table id="depsTable"> </table>
<style>
.da_htmlTableHeader {
background-color: gold;
}
</style>
<script>
</script>
Step 3
In the <script></script>
block, we are first going to create a RemoteDataAdapter object through which you will interact with the server. The constructor can take up to 4 arguments which defines the specifics of the connection, by default you can just supply the url of the server you wish to connect to.
The next thing we define is a DataTable object that will represent the table and the rows of data that we wish to access in the schema. Here we pass the name of the table we are interested in to the constructor. Once we have filled the object with the data from the server, we can use methods to access, modify and add data.
var Adapter = new RemObjects.DataAbstract.RemoteDataAdapter("http://localhost:7099/bin/");
var Table = new RemObjects.DataAbstract.DataTable("deps");
Step 4
After defining the above variables, we are going to use the Adapter
variable to log into the server. We pass two arguments to the login
method, the first is a login string that contains the name (User
) and password ('Password') of a user that is allowed to access the server as well as the name of the domain (Domain
) and schema (Schema
) that the user is attempting to access. The second argument is an anonymous callback function that will be called when if the login attempt is successful which we will examine in a moment. The final argument is a utility method that is called when the login attempt fails.
The getData
method takes 4 arguments, the first of which is the Table
object that we created in Step 3, that will be filled with the data in the table. The RemObjects.DataAbstract.Util.createRequestInfo
method creates a TableRequestInfo
object which we can use to constrain what data is retrieved from the server. The next argument is an anonymous function that will be called if the call to getData
is successful, here we are using one of the helper functions to print out the retrieved data into the html table we identified as depsTable
. The last argument is again a utility method that is called when the login attempt fails.
Taking a closer look at the createRequestInfo
function, it takes 4 arguments which in order are:
includeSchema
which is a boolean which indicates if information about the schema should be returned. Normally the client will already know about the schema and including it will add some additional overhead, however there may be situations where you need to update the schema information in the client.maxRecords
is an integer value that indicates the maximum number of records to return when retrieving the data. If you use-1
then the call will return all the records, however when dealing with large tables that is inadvisable.userFilter
allows you to specify an optional string that can be used to filter the data in the table. This should be left blank, and Dynamic Where should instead be used for filtering rows.parameters
- this is an optional array of parameters which can be passed along to the server which it can then act on.
Adapter.login("User=simple;Password=simple;Domain=DASamples;Schema=Simple", function() {
Adapter.getData(Table, RemObjects.DataAbstract.Util.createRequestInfo(true, -1, '', []),
function() {
new RemObjects.DataAbstract.Views.HtmlTableView(Table, 'depsTable');
}, RemObjects.UTIL.showError)
}, RemObjects.UTIL.ShowError);
Having added all the code, save the html file and access it in a browser window; making sure that an instance of Relativity server is currently running.
Sample Output
When you load the webpage in your browser you will be a basic table displayed on the page which contains all the records in the deps table.
Id | Name | Phone |
1 | Sales | (873)456-78-99 |
2 | Incomes | (873)456-78-88 |
Full Code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://localhost:7099/js/RemObjectsSDK.js" type="text/javascript"></script>
<script src="http://localhost:7099/js/DataAbstract.js" type="text/javascript"></script>
<script src="http://localhost:7099/js/DataAbstract4_intf.js" type="text/javascript"></script>
</head>
<body>
<table id="depsTable"> </table>
<style>
.da_htmlTableHeader {
background-color: gold;
}
</style>
<script>
var Adapter = new RemObjects.DataAbstract.RemoteDataAdapter("http://localhost:7099/bin/");
var Table = new RemObjects.DataAbstract.DataTable("deps");
Adapter.login("User=simple;Password=simple;Domain=DASamples;Schema=Simple", function() {
Adapter.getData(Table, RemObjects.DataAbstract.Util.createRequestInfo(true, -1, '', []),
function() {
new RemObjects.DataAbstract.Views.HtmlTableView(Table, 'depsTable');
}, RemObjects.UTIL.showError)
}, RemObjects.UTIL.ShowError);
</script>
</body>
</html>