Page tree


Obtains the internal identifier that corresponds to a choice value for use in SQL-based expressions.


 long id = ew.EWGetChoiceLineId(String sessionId, String
    String fieldName, String value);


Use EWGetChoiceLineId to obtain the internal identifier that corresponds to the choice text value for further use in SQL-based expressions such as the where parameter of EWSelectFromTable or the value of searchSQL property when forging links to other tables via 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 the EWGetChoiceLineId call to obtain the id value at runtime immediately before the SQL call.

Rules and Guidelines

When querying for choice value identifiers, consider the following rules and guidelines:

  • The value parameter is intentionally specified as String rather than an enumerated WSDL type. This is to give client applications more flexibility.

If the client needs to lookup the identifier of the choice value enumerated in WSDL, the client should convert the enumerated value into String. Since enumerated WSDL types that correspond to the choice values are based on Strings, this should always be possible although specific details depend on the client Web Services environment used. 

When converting one of the WSChoice_ values back to String, please note that the original text values have undergone the following transformations:

  1. Spaces replaced by "_"
  2. Dashes replaced by "MINUS"
  3. Pluses replaced by "PLUS"
  4. Prefixed with "OPTION_"
  5. Converted to upper case

You need to perform the reverse transformation to get to the text value.

  • If the factors that trigger the change of the internal choice identifiers are somehow detected on the client, then the values returned by this call can be safely cached on a per KB basis between multiple calls. As described above, the internal choice field identifiers can be changed when a knowledgebase is copied or re-imported, or if the values in the choice list are re-created.

Example Task

In MyKB knowledgebase as user A, find all cases with High priority. 

The task is completed by performing the following steps:

  1. Login to MyKB with "A" and "password", English as the locale language.
  2. Obtain the identifier for the choice value High for the field Priority in the table Case.
  3. Run the SQL query to obtain the identifiers.
  4. Logout.

Sample Code - Java

You can generate a sample Web Services code for any table by selecting Setup > Tables > [Edit Table] > API > Download Sample.

 public long[] selectCasesPriorityHigh() throws Exception {
               EWServiceAPI binding = new EWServiceAPIServiceLocator().getMyKB();
    String sessionId = binding.EWLogin("MyKB", "A", "password", "en");
    try {
    long high = binding.EWGetChoiceLineId(sessionId, "case", "priority",
    long ids[] = binding.EWSelectFromTable(sessionId, "case",
    return ids;
    } catch (EWSessionException e) {
    // Normally the client should just re-login and re-try the call.
    throw e;
    } catch (EWWrongDataException e) {
    // Since the field name and the choice value being looked up are most
    // hard-coded this is really a show-stopper that should be reported to
    // developer/implementer
    throw e;
    } catch (EWIntegrityException e) {
    // Since the table name is hard-coded this is a show-stopper that
    should be
    // reported to the developer/implementer
    throw e;
    } catch (EWUnexpectedException e) {
    // This exception should be reported to the vendor.
    // The message contains a token that will help to trace the root cause
    // the problem.
    throw e;
    } finally {







Session token.



The name of the table where the choice field is located.



The name of the choice field in the table.



The choice text value.


The identifier that corresponds to the choice text value.


EWSessionException - client not logged in or the session has expired; client should re-login. 

EWWrongDataException - the specified field does not exist in the table or the choice value passed cannot be found. 

EWIntegrityException - the specified table cannot be found or its primary key cannot be identified. 

EWUnexpectedException - an unexpected exception has happened; user should report this for investigation.