---
title: "REST - GetChoiceLineId"
canonical: "https://help.agiloft.com/space/HELP/43714380/REST+-+GetChoiceLineId"
format: markdown
---
> Macro (anchor)

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](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43714549), or used in the query text when linking to other tables in linked field sets.

- **Returns**: the ID of the choice list element.
- **Supported Content-Type**: <span style="color: #505050">application/</span>x-www-form-urlencoded
- Accepts a URL with URL-encoded parameters and record data. For more information about general URL conventions, see [REST Interface](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).
- Additionally, the URL must contain the name of the choice field and the choice list element value.

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 Agiloft 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: 

```javascript
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: 

```javascript
 EWREST_choiceLineId = '1';
```

## JavaScript Example

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

```javascript
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');
    }
```

# Error Codes

These error codes are for EWGetChoiceLineID only, but are not an extensive list of possible error codes. For any errors not listed here, consult the General Error Codes section of [https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778](https://agiloft-public.atlassian.net/wiki/spaces/HELP/pages/43715778).

|  |  |  |  |
| --- | --- | --- | --- |
| Scenario | Type | Code | Description |
| No choice line found for the provided field | VALIDATION | 400 | EWWrongDataException → No choice line found for value   <fieldName> |
| field or value is missing in the request | VALIDATION | 500 | EWUnexpectedException   → unexpected exception |

> Macro (hide-if)
> 
> #### Related articles
> 
> > Macro (contentbylabel)