The EWGetChoiceLineID operation is used to retrieve the internal ID for a choice value, which can be used in SQL-based expressions. It returns the identifier of the choice list element. This can be used for the "where" parameter in operations like Select, or used in the query text when linking to other tables in linked field sets.

SQL-based expressions are evaluated on the database level where choice values are stored as identifiers. These identifiers change if the knowledgebase is copied or re-imported, or the values in the choice list are re-created. It is therefore advisable to use this operation to obtain the ID value at runtime, immediately before the SQL call.

If the factors that trigger the change of the internal choice identifiers, such as knowledgebase copy or re-import, or choice list values are re-created, are detected on the client, then the values returned by this call can be safely cached on a per KB basis between multiple calls.

Example

Assume an instance of  is available on localhost, port 8080 and is called "Demo". Obtain the identifier for choice value 'High' for the field 'Priority' in the table 'Case'.

The following request is issued: 

https://localhost:8080/ewws/EWGetChoiceLineId?$KB=Demo&$login=admin&$password=qwerty&$table=case&$lang=en&field=priority&value=High 

If there were no matching choice list values found, the HTTP code 400 will be returned with a brief explanation of the problem.

The following result will be returned in the case of the text value being successfully translated into a numeric identifier: 

 EWREST_choiceLineId = '1';

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/EWGetChoiceLineId?$KB=Demo
        &$table=case&$login=admin&$password=qwerty
        &$lang=en&field=priority&value=High');
    }

Related articles