servicenow.community.soap
Class GlideRecord

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

public class GlideRecord
extends java.lang.Object

Contains an XML document (in the form of a JDOM Element) which has been retrieved from ServiceNow. The only way to obtain one of these is to use GlideTable.get() or GlideTable.getRecords().

Author:
Giles Lewis

Field Summary
protected  GlideDateTime createdTimestamp
           
protected  org.jdom2.Element element
           
protected  GlideKey key
           
protected  GlideTable table
           
protected  GlideDateTime updatedTimestamp
           
 
Constructor Summary
protected GlideRecord(GlideTable table, org.jdom2.Element element)
           
 
Method Summary
 boolean getBoolean(java.lang.String fieldname)
           
 GlideDateTime getCreatedTimestamp()
          Get sys_created_on from a GlideRecord object.
 GlideDateTime getDate(java.lang.String fieldname)
          Return a Date field as a GlideDateTime.
 GlideDateTime getDateTime(java.lang.String fieldname)
          Return a DateTime field as a GlideDateTime.
 java.lang.Integer getDuration(java.lang.String fieldname)
          Return a duration field in seconds.
 java.lang.String getField(java.lang.String fieldname)
          Get the value of a field from a GlideRecord.
 int getInt(java.lang.String fieldname)
           
 GlideKey getKey()
          Get the sys_id from a GlideRecord object.
 GlideRecord getRecord(java.lang.String fieldname)
          If a reference field in a GlideRecord contains a valid sys_id, then return the GlideRecord to which the reference field points.
 GlideRecord getRecord(java.lang.String fieldname, GlideTable table)
          If a reference field in a GlideRecord contains a valid sys_id, then return the GlideRecord to which the reference field points.
 GlideKey getReference(java.lang.String fieldname)
           
 GlideTable getTable()
           
 GlideDateTime getUpdatedTimestamp()
          Get sys_updated_on from a GlideRecord object.
 java.lang.String getXML()
          Returns this object as an XML string.
 int numFields()
           
 void setBoolean(java.lang.String fieldname, boolean value)
           
 void setField(java.lang.String fieldname, java.lang.String fieldvalue)
           
 void setInt(java.lang.String fieldname, int value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

table

protected final GlideTable table

key

protected final GlideKey key

element

protected final org.jdom2.Element element

updatedTimestamp

protected GlideDateTime updatedTimestamp

createdTimestamp

protected GlideDateTime createdTimestamp
Constructor Detail

GlideRecord

protected GlideRecord(GlideTable table,
                      org.jdom2.Element element)
               throws SoapResponseException
Throws:
SoapResponseException
Method Detail

getTable

public GlideTable getTable()

numFields

public int numFields()

getXML

public java.lang.String getXML()
Returns this object as an XML string. To be used only for debugging.


getField

public java.lang.String getField(java.lang.String fieldname)
                          throws InvalidFieldNameException
Get the value of a field from a GlideRecord. If the table has no field by this name then an exception will be thrown. If the field is empty (zero length) or missing then return null.

Parameters:
fieldname - Name of GlideRecord field
Returns:
Field value as a string or null if the field is missing or has zero length.
Throws:
InvalidFieldNameException

getKey

public GlideKey getKey()
Get the sys_id from a GlideRecord object.

Returns:
sys_id

getReference

public GlideKey getReference(java.lang.String fieldname)
                      throws InvalidFieldNameException
Throws:
InvalidFieldNameException

getUpdatedTimestamp

public GlideDateTime getUpdatedTimestamp()
Get sys_updated_on from a GlideRecord object.


getCreatedTimestamp

public GlideDateTime getCreatedTimestamp()
Get sys_created_on from a GlideRecord object.


getRecord

public GlideRecord getRecord(java.lang.String fieldname,
                             GlideTable table)
                      throws java.io.IOException
If a reference field in a GlideRecord contains a valid sys_id, then return the GlideRecord to which the reference field points. If the reference field is null then return null. This function requires a GlideTable object as the second parameter so that the function will know which table to query.

Parameters:
fieldname - Name of the reference field.
table - GlideTable to which the reference field points, or null if the value of the reference field is null.
Returns:
GlideRecord to which the reference field points.
Throws:
java.io.IOException

getRecord

public GlideRecord getRecord(java.lang.String fieldname)
                      throws java.io.IOException
If a reference field in a GlideRecord contains a valid sys_id, then return the GlideRecord to which the reference field points. If the reference field is null then return null.

This function can be used to simulate the "dot walking" behavior of JavaScript. The following example will set name to the manager of the "Network Support" group. The get function returns a GlideRecord for the sys_user_group table and the the getRecord function returns a GlideRecord for the sys_user table. However, if the group has no manager this code will throw a NullPointerException.

 String name = instance.table("sys_user_group").get("name", "Network Support").
   getRecord("manager").getField("name");
 

Parameters:
fieldname - Name of the reference field.
Returns:
A retrieved copy of the GlideRecord to which the reference field points, or null if the value of the reference field is null.
Throws:
java.io.IOException

getInt

public int getInt(java.lang.String fieldname)

getDateTime

public GlideDateTime getDateTime(java.lang.String fieldname)
                          throws java.text.ParseException
Return a DateTime field as a GlideDateTime. For a Java date use getDateTime(fieldname).toDate().

Throws:
java.text.ParseException

getDate

public GlideDateTime getDate(java.lang.String fieldname)
                      throws java.text.ParseException
Return a Date field as a GlideDateTime. For a Java date use getDate(fieldname).toDate().

Throws:
java.text.ParseException

getBoolean

public boolean getBoolean(java.lang.String fieldname)
                   throws java.text.ParseException
Throws:
java.text.ParseException

getDuration

public java.lang.Integer getDuration(java.lang.String fieldname)
                              throws java.text.ParseException
Return a duration field in seconds.

Throws:
java.text.ParseException

setField

public void setField(java.lang.String fieldname,
                     java.lang.String fieldvalue)

setInt

public void setInt(java.lang.String fieldname,
                   int value)

setBoolean

public void setBoolean(java.lang.String fieldname,
                       boolean value)