Class ServiceNowAPITool


  • public class ServiceNowAPITool
    extends java.lang.Object
    ServiceNow API toolbox
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DATA_PATH
      Data path
      static java.lang.String METADATA_PATH
      Metadata path
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long count​(java.lang.String query)
      Run a count-only search query
      org.json.JSONObject getConfig()
      Get configuration
      java.lang.String getFieldDefault​(org.json.JSONObject fmd)
      Get default value from field metadata and type
      java.lang.String getFieldFilter​(ObjectField field)
      Get ServiceNow filter from field filter
      java.lang.String getFieldHint​(org.json.JSONObject fmd)
      Get hint from field metadata and type
      java.lang.String getFieldLabel​(org.json.JSONObject fmd)
      Get label from field metadata and type
      ListOfValuesData getFieldListOfValues​(org.json.JSONObject fmd, java.lang.String prefix)
      Get list of values from field metadata and type
      boolean getFieldMore​(org.json.JSONObject fmd, int type)
      Get visibility from field metadata and type
      java.lang.String getFieldName​(org.json.JSONObject fmd)
      Get name from field metadata
      java.lang.String getFieldReferencedField​(org.json.JSONObject fmd)
      Get referenced field of referenced table from field metadata
      java.lang.String getFieldReferencedTable​(org.json.JSONObject fmd)
      Get reference to table name from field metadata
      java.lang.String getFieldRendering​(org.json.JSONObject fmd, int type)
      Get rendering from field metadata and type
      int getFieldSearch​(org.json.JSONObject fmd, int type)
      Get search mode from field metadata and type
      int getFieldSearchReq​(org.json.JSONObject fmd, int type, int search)
      Get required search mode from field metadata and type
      int getFieldSize​(org.json.JSONObject fmd, int type)
      Get size from field metadata and type
      int getFieldType​(org.json.JSONObject fmd)
      Get type from field metadata
      int getFieldUpdatable​(org.json.JSONObject fmd, int type)
      Get field updatable mode from field metadata and type
      java.lang.String getFieldValue​(java.lang.String name, int type, org.json.JSONObject record)
      Get field value from ServiceNow value
      int getFieldVisibility​(org.json.JSONObject fmd, int type)
      Get visibility from field metadata and type
      java.lang.String getTableName​(org.json.JSONObject md)
      Get table name from metadata
      boolean isFieldRequired​(org.json.JSONObject fmd, int type)
      Is required from field metadata and type
      org.json.JSONObject metadata​(java.lang.String table)
      Get table metadata
      org.json.JSONArray search​(java.lang.String query, java.lang.String fields, long limit, long offset)
      Run a search query
      org.json.JSONObject select​(java.lang.String rowId, java.lang.String fields)
      Run a select
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • METADATA_PATH

        public static final java.lang.String METADATA_PATH
        Metadata path
        See Also:
        Constant Field Values
    • Constructor Detail

      • ServiceNowAPITool

        public ServiceNowAPITool​(Grant g,
                                 java.lang.String config)
                          throws java.lang.Exception
        Constructor
        Parameters:
        g - Grant
        config - Configuration as JSON string
        Throws:
        java.lang.Exception
      • ServiceNowAPITool

        public ServiceNowAPITool​(Grant g,
                                 org.json.JSONObject config)
                          throws java.lang.Exception
        Constructor
        Parameters:
        g - Grant
        config - Configuration as JSON object
        Throws:
        java.lang.Exception
    • Method Detail

      • getConfig

        public org.json.JSONObject getConfig()
        Get configuration
        Returns:
        Configuration as JSON object
      • metadata

        public org.json.JSONObject metadata​(java.lang.String table)
                                     throws java.lang.Exception
        Get table metadata
        Parameters:
        table - Table name
        Returns:
        Table metadata as JSON object
        Throws:
        java.lang.Exception
      • getTableName

        public java.lang.String getTableName​(org.json.JSONObject md)
        Get table name from metadata
        Parameters:
        md - Metadata
        Returns:
        Field name
      • getFieldName

        public java.lang.String getFieldName​(org.json.JSONObject fmd)
        Get name from field metadata
        Parameters:
        fmd - Field metadata
        Returns:
        Field name
      • getFieldLabel

        public java.lang.String getFieldLabel​(org.json.JSONObject fmd)
        Get label from field metadata and type
        Parameters:
        fmd - Field metadata
        Returns:
        Field label
      • getFieldHint

        public java.lang.String getFieldHint​(org.json.JSONObject fmd)
        Get hint from field metadata and type
        Parameters:
        fmd - Field metadata
        Returns:
        Field hint
      • getFieldType

        public int getFieldType​(org.json.JSONObject fmd)
        Get type from field metadata
        Parameters:
        fmd - Field metadata
        Returns:
        Field type (ObjectField.TYPE_*)
      • getFieldSize

        public int getFieldSize​(org.json.JSONObject fmd,
                                int type)
        Get size from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        Field size
      • getFieldDefault

        public java.lang.String getFieldDefault​(org.json.JSONObject fmd)
        Get default value from field metadata and type
        Parameters:
        fmd - Field metadata
        Returns:
        Field size
      • getFieldRendering

        public java.lang.String getFieldRendering​(org.json.JSONObject fmd,
                                                  int type)
        Get rendering from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        Field rendering
      • getFieldReferencedTable

        public java.lang.String getFieldReferencedTable​(org.json.JSONObject fmd)
        Get reference to table name from field metadata
        Parameters:
        fmd - Field metadata
        Returns:
        Referenced table name name or null
      • getFieldReferencedField

        public java.lang.String getFieldReferencedField​(org.json.JSONObject fmd)
        Get referenced field of referenced table from field metadata
        Parameters:
        fmd - Field metadata
        Returns:
        Referenced field name or null
      • getFieldListOfValues

        public ListOfValuesData getFieldListOfValues​(org.json.JSONObject fmd,
                                                     java.lang.String prefix)
        Get list of values from field metadata and type
        Parameters:
        fmd - Field metadata
        prefix - List of value prefix
        Returns:
        List of values
      • getFieldVisibility

        public int getFieldVisibility​(org.json.JSONObject fmd,
                                      int type)
        Get visibility from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        Field visibility
      • getFieldMore

        public boolean getFieldMore​(org.json.JSONObject fmd,
                                    int type)
        Get visibility from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        Field visibility
      • getFieldSearch

        public int getFieldSearch​(org.json.JSONObject fmd,
                                  int type)
        Get search mode from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        Field search mode
      • getFieldSearchReq

        public int getFieldSearchReq​(org.json.JSONObject fmd,
                                     int type,
                                     int search)
        Get required search mode from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        search - Optional search mode (obtained from getFieldSearch), or -1
        Returns:
        Field required search mode
      • isFieldRequired

        public boolean isFieldRequired​(org.json.JSONObject fmd,
                                       int type)
        Is required from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        True if field is required
      • getFieldUpdatable

        public int getFieldUpdatable​(org.json.JSONObject fmd,
                                     int type)
        Get field updatable mode from field metadata and type
        Parameters:
        fmd - Field metadata
        type - Optional type (obtained from getFieldType), or -1
        Returns:
        Field updatable mode
      • getFieldFilter

        public java.lang.String getFieldFilter​(ObjectField field)
        Get ServiceNow filter from field filter
        Parameters:
        field - Field
        Returns:
        ServiceNow filter
      • getFieldValue

        public java.lang.String getFieldValue​(java.lang.String name,
                                              int type,
                                              org.json.JSONObject record)
        Get field value from ServiceNow value
        Parameters:
        name - Field name
        type - Field type
        record - ServiceNow record
        Returns:
        Field value
      • count

        public long count​(java.lang.String query)
                   throws java.lang.Exception
        Run a count-only search query
        Parameters:
        query - Search query
        Returns:
        Search count
        Throws:
        java.lang.Exception
      • search

        public org.json.JSONArray search​(java.lang.String query,
                                         java.lang.String fields,
                                         long limit,
                                         long offset)
                                  throws java.lang.Exception
        Run a search query
        Parameters:
        query - Search query
        fields - Fields to return (null means all fields)
        Returns:
        Search result as JSON array
        Throws:
        java.lang.Exception
      • select

        public org.json.JSONObject select​(java.lang.String rowId,
                                          java.lang.String fields)
                                   throws java.lang.Exception
        Run a select
        Parameters:
        rowId - Record row ID
        fields - Fields to return (null means all fields)
        Returns:
        Select result as JSON object
        Throws:
        java.lang.Exception