servicenow.community.soap
Class GlideTable

java.lang.Object
  extended by servicenow.community.soap.GlideTable

public class GlideTable
extends java.lang.Object

Used to access a ServiceNow table. The recommended way to obtain a GlideTable object is the Instance.table() method. This class will load the table schema from sys_dictionary when it is instantiated.

Author:
LewisGF

Field Summary
static int DEFAULT_CHUNK_SIZE
           
static int MAX_CHUNK_SIZE
           
 
Constructor Summary
GlideTable(Instance instance, java.lang.String tablename)
          The recommended way to obtain a GlideTable object is the Instance.table() method.
 
Method Summary
 void attachFile(GlideKey key, java.io.File file)
          This method attaches a file to a record in a table.
 BulkFetcher bulkFetcher()
           
 BulkFetcher bulkFetcher(GlideFilter query)
           
 boolean deleteRecord(GlideKey sysid)
          Delete a record from the table.
 GlideRecord get(GlideKey sysid)
          Returns a single record based on a sys_id.
 GlideRecord get(java.lang.String fieldname, java.lang.String fieldvalue)
          Retrieves a single record.
 GlideKeyList getKeys()
           
 GlideKeyList getKeys(servicenow.community.soap.Parameters params)
           
 java.lang.String getName()
           
 org.jdom2.Namespace getNamespace()
           
 java.lang.String getParentName()
           
 GlideRecordList getRecords(GlideFilter filter)
           
 GlideRecordList getRecords(GlideKeyList list)
           
 GlideRecordList getRecords(GlideKeyList list, int fromIndex, int toIndex)
           
 GlideRecordList getRecords(servicenow.community.soap.Parameters params)
           
 GlideRecordList getRecords(java.lang.String fieldname, java.lang.String fieldvalue)
           
 GlideTableSchema getSchema()
          Returns the table schema as obtained from sys_dictionary when the class was instantiated.
 GlideKey insert(FieldValues fields)
          This is the normal method used to insert a new record.
 GlideKey insert(GlideRecord rec)
          This insert method is only used when copying data.
protected  GlideTable loadSchema()
           
 boolean readable()
          Returns true if records can be read from a table.
 GlideTable setChunkSize(int chunkSize)
           
 GlideTable setDisplayValues(boolean dv)
           
 GlideTable setValidate(boolean validate)
           
 GlideKey update(GlideKey sysid, FieldValues fields)
           
 GlideKey update(GlideRecord rec)
           
 boolean validate()
           
 void validateFields(FieldValues values)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHUNK_SIZE

public static final int DEFAULT_CHUNK_SIZE
See Also:
Constant Field Values

MAX_CHUNK_SIZE

public static final int MAX_CHUNK_SIZE
See Also:
Constant Field Values
Constructor Detail

GlideTable

public GlideTable(Instance instance,
                  java.lang.String tablename)
           throws java.io.IOException,
                  InvalidTableNameException
The recommended way to obtain a GlideTable object is the Instance.table() method.

Parameters:
tablename -
instance -
Throws:
org.jdom2.JDOMException
java.io.IOException
InvalidTableNameException
Method Detail

getName

public java.lang.String getName()

getParentName

public java.lang.String getParentName()

getNamespace

public org.jdom2.Namespace getNamespace()

loadSchema

protected GlideTable loadSchema()
                         throws java.io.IOException
Throws:
java.io.IOException

getSchema

public GlideTableSchema getSchema()
Returns the table schema as obtained from sys_dictionary when the class was instantiated.


setChunkSize

public GlideTable setChunkSize(int chunkSize)

setValidate

public GlideTable setValidate(boolean validate)

validate

public boolean validate()

setDisplayValues

public GlideTable setDisplayValues(boolean dv)
                            throws java.io.IOException
Throws:
java.io.IOException

validateFields

public void validateFields(FieldValues values)
                    throws InvalidFieldNameException
Throws:
InvalidFieldNameException

insert

public GlideKey insert(GlideRecord rec)
                throws java.io.IOException
This insert method is only used when copying data. It requires as input a GlideRecord, and the only proper way to obtain a GlideRecord is to read it. Columns names beginning with "sys_" will not be inserted.

The recommended and safer way to insert records is to use the GlideTable.insert(FieldValues) method.

Parameters:
rec - Record obtained from a previous get() or getRecords()
Returns:
sys_id of the inserted record.
Throws:
java.io.IOException

insert

public GlideKey insert(FieldValues fields)
                throws java.io.IOException
This is the normal method used to insert a new record. It requires as input an initialized FieldValues object.

Here are two equivalent approaches.

 instance.table("insert").insert(new FieldValues().
   set("category","network").
   set("short_description","a network error has occurred"));
   
 new FieldValues().
   set("category","network").
   set("short_description","a network error has occurred").
   insert(instance.table("incident")); 
 

Parameters:
fields - FieldValues object containing the values to be inserted.
Returns:
sys_id of the inserted record.
Throws:
java.io.IOException

deleteRecord

public boolean deleteRecord(GlideKey sysid)
                     throws java.io.IOException
Delete a record from the table.

Parameters:
sysid - sys_id of the record to be deleted.
Returns:
true if the record is deleted, false if the record is not found.
Throws:
java.io.IOException
org.jdom2.JDOMException

update

public GlideKey update(GlideRecord rec)
                throws java.io.IOException
Throws:
java.io.IOException

update

public GlideKey update(GlideKey sysid,
                       FieldValues fields)
                throws java.io.IOException
Throws:
java.io.IOException

get

public GlideRecord get(java.lang.String fieldname,
                       java.lang.String fieldvalue)
                throws java.io.IOException,
                       java.lang.IndexOutOfBoundsException
Retrieves a single record. This function should be used in cases where the field value is known to be unique. If no qualifying records are found this function will return null. If multiple qualifying recrods are found this function will throw an IndexOutOfBoundsException.
 GlideRecord rec = instance.table("sys_user_group").get("name", "Network Support");
 

Parameters:
fieldname - Field name, e.g. "number" or "name"
fieldvalue - Field value
Returns:
A GlideRecord object.
Throws:
java.io.IOException
java.lang.IndexOutOfBoundsException - Thrown if more than one record matches the fieldvalue.

get

public GlideRecord get(GlideKey sysid)
                throws java.io.IOException
Returns a single record based on a sys_id. If no qualifying record is found then null is returned.

GlideRecord rec = instance.table("sys_user_group").get(new GlideKey("287ebd7da9fe198100f92cc8d1d2154e"));

Parameters:
sysid -
Returns:
Retrieved copy of the GlideRecord
Throws:
java.io.IOException

readable

public boolean readable()
                 throws java.io.IOException,
                        SoapRecordLimitExceeded
Returns true if records can be read from a table. The ServiceNow Web Services API does not provide a good method to determine if a table is readable. There is no way to distinguish a table which has been blocked by Access Controls from a table which is empty. This method attempts to read a single record from the table. If no records are returned, then it is assumed that the table is not readable.

Returns:
true if at least one record can be read from this table, otherwise false
Throws:
java.io.IOException
SoapRecordLimitExceeded

getRecords

public GlideRecordList getRecords(servicenow.community.soap.Parameters params)
                           throws java.io.IOException,
                                  SoapRecordLimitExceeded
Throws:
java.io.IOException
SoapRecordLimitExceeded

getRecords

public GlideRecordList getRecords(GlideFilter filter)
                           throws java.io.IOException,
                                  SoapRecordLimitExceeded
Throws:
java.io.IOException
SoapRecordLimitExceeded

getRecords

public GlideRecordList getRecords(java.lang.String fieldname,
                                  java.lang.String fieldvalue)
                           throws java.io.IOException,
                                  SoapRecordLimitExceeded
Throws:
java.io.IOException
SoapRecordLimitExceeded

getRecords

public GlideRecordList getRecords(GlideKeyList list)
                           throws java.io.IOException
Throws:
java.io.IOException

getRecords

public GlideRecordList getRecords(GlideKeyList list,
                                  int fromIndex,
                                  int toIndex)
                           throws java.io.IOException
Throws:
java.io.IOException

getKeys

public GlideKeyList getKeys(servicenow.community.soap.Parameters params)
                     throws java.io.IOException
Throws:
java.io.IOException

getKeys

public GlideKeyList getKeys()
                     throws java.io.IOException
Throws:
java.io.IOException

bulkFetcher

public BulkFetcher bulkFetcher(GlideFilter query)
                        throws java.io.IOException
Throws:
java.io.IOException

bulkFetcher

public BulkFetcher bulkFetcher()
                        throws java.io.IOException
Throws:
java.io.IOException

attachFile

public void attachFile(GlideKey key,
                       java.io.File file)
                throws java.io.IOException
This method attaches a file to a record in a table.

Parameters:
key - The sys_id of the record to which the file is to be attached.
file - The file that is to be attached.
Throws:
java.io.IOException