Page tree

REST - Select

The EWSelect operation performs a select on the specified table, and returns the number of records found along with an encoded list of record IDs.

  • Returns: the number of records found and an encoded list of record IDs.
  • Supported Content-Type: application/x-www-form-urlencoded
  • Accepts a URL with URL-encoded parameters and record data. For more information about general URL conventions, see REST Interface.
  • Additionally, the URL must contain the where clause of the SELECT query to be performed. Queries in the URL must use %N equivalent operators. For instance, in place of >, use %3E%27.

Notes

Only one SQL statement is accepted per call. The API automatically and transparently applies security filters to prevent unauthorized access to information. 

These SQL queries operate on the database level, and should be written using the dbname column names that can be found in the Table Wizard in user interface. Some values for high-level complex field types may have very different representation from what is seen in the GUI. For example, see GetChoiceLineId for the special handling of choice values.

The SQL query supplied should only include the where clause from a construct similar to: 

select primary-key-field-name from table-name where ...

This returns the number of records found, and an encoded data list of record ID, if any were found.

It is possible to limit the number of records returned using the tools available in the underlying database you use for your instance of Agiloft. For example, if you use MySQL as the underlying database, "limit 0,200" limits the number of the returned records to 200.

The order of records returned is determined by the underlying database, and Select doesn't offer any additional control over this default order. If you need to impose a sort order on the records, consider using EWSearch instead, where you can specify a saved search that imposes a sort order.

Example 1

Assume an instance of  Agiloft is available on localhost, port 8080 and is called "Demo". List the Service Request records assigned to 'Ralph Knowles'.

The following request is issued: 

https://localhost:8080/ewws/EWSelect?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&where=assigned_person='Ralph Knowles'

If there are no records found, the following result will be returned: 

EWREST_id_length = '0';
The following result will be returned in the case of three records being found: 
EWREST_id_length = '3';
EWREST_id_0 = '150';
EWREST_id_1 = '169';
EWREST_id_2 = '325';

Example 2

Assume an instance of  Agiloft is available on localhost, port 8080 and Demo KB. List the records with summaries containing word 'new’ (summary like '%new%').

The following request is issued: 

https://localhost:8080/ewws/EWSelect?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&where=summary%20like%20%27%25new%25%27

If there are no records found, the following result will be returned: 

EWREST_id_length = '0'; 

The following result will be returned in the case of seven records being found: 

EWREST_id_length = '7';
EWREST_id_0 = '145';
EWREST_id_1 = '147';
EWREST_id_2 = '148';
EWREST_id_3 = '149';
EWREST_id_4 = '151';
EWREST_id_5 = '298';
EWREST_id_6 = '318';

JavaScript Example

Here is an example for a JavaScript-based client that invokes the REST interface via AJAX: 

function xmlhttpGet (strURL) {
        var xmlHttpReq=false;
        var self=this;
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
            try {
                netscape.security.PrivilegeManager.
enablePrivilege("UniversalBrowserRead");
            } catch (e) {
                alert("Permission UniversalBrowserRead denied.");
            }
            self.xmlHttpReq=new XMLHttpRequest();
        }// IE
        else if (window.ActiveXObject) {
            self.xmlHttpReq=new ActiveXObject("Microsoft.xmlHTTP");
        }
        self.xmlHttpReq.open('GET', strURL, true);
        self.xmlHttpReq.onreadystatechange=requestComplete;
        self.xmlHttpReq.send(null);
    }
    function requestComplete() {
        if (xmlHttpReq.readyState==4||xmlHttpReq.readyState=="complete") {
            eval (self.xmlHttpReq.responseText);
            alert ("Id of new ticket"+EWREST_id);
        }
    }
    function main() {
        xmlhttpGet(' https://localhost:8080/ewws/EWSelect?$KB=Demo&$login=admin&$password=qwerty&$table=helpdesk_case&$lang=en&where=summary%20like%20%27%25new%25%27');
    }