Skip Navigation
Expand
Querying custom fields through ROQL
Answer ID 6390   |   Last Review Date 03/18/2019

How do I query for custom fields using ROQL?

Environment:

ROQL, SOAP API

Resolution:

In order to query for custom fields through ROQL an ObjectTemplate must be supplied with the query. While the code that will produce a SOAP envelope containing a ROQL query for custom fields can be written differently when using different access points, the resultant SOAP envelope will be similar. Utilizing the QueryObjects call with templating will result in a SOAP envelope like the following:

<s:Envelope xmlns:u='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>
  <s:Header>
    <h:ClientInfoHeader xmlns='urn:messages.ws.rightnow.com/v1_2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:h='urn:messages.ws.rightnow.com/v1_2' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
      <AppID>Basic Objects Sample</AppID>
    </h:ClientInfoHeader>
    <o:Security s:mustUnderstand='1' xmlns:o='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
      <o:UsernameToken u:Id='uuid-84093390-78b8-44db-acba-6a792c0a22a3-1'>
        <o:Username>user</o:Username>
        <o:Password>password</o:Password>
      </o:UsernameToken>
    </o:Security>
  </s:Header>
  <s:Body xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
    <QueryObjects xmlns='urn:messages.ws.rightnow.com/v1_2'>
      <Query>SELECT Incident FROM Incident WHERE ID = 1</Query>
      <ObjectTemplates xmlns:q1='urn:objects.ws.rightnow.com/v1_2' xsi:type='q1:Incident'>
        <q1:CustomFields />
      </ObjectTemplates>
      <PageSize>10000</PageSize>
    </QueryObjects>
  </s:Body>
</s:Envelope>

The following pages of documentation contain additional information on this topic:
QueryObjects
ROQL and Common Objects
ROQL and Custom Objects 

Alternatively, custom fields can be queried for using the QueryCSV function without the use of an object template.

Cause:

The QueryObjects function is designed to return objects. Custom fields are not objects as they contain only the data type that they are set to (integer, menu, string, etc), so a template must be supplied to apply the custom field information to.

Available Languages for this Answer:

Notify Me
The page will refresh upon submission. Any pending input will be lost.