package
1.7.0-preview20241215
Repository: https://github.com/recolabs/servicenow-sdk-go.git
Documentation: pkg.go.dev

# README

Table API

The Table API is an essential interface provided by ServiceNow, enabling developers to perform Create, Read, Update, and Delete (CRUD) operations on the tables within a ServiceNow instance. This guide offers comprehensive instructions on utilizing the API endpoints, with code examples in Go.

Please ensure that any strings enclosed in curly braces {} are replaced with actual values before using the examples. The documentation demonstrates two approaches for interacting with the API:

  1. Fluent Interface Pattern: This approach allows for chaining methods in a single expression.
  2. Building Request: This method involves constructing the request step by step.

Initial Setup

To begin using the API, you must first configure your environment. Below is the standard setup code utilized across all examples:

package main

import (
    tableapi "github.com/RecoLabs/servicenow-sdk-go/table-api"
)

func main() {
    // Define the base URL of your ServiceNow instance
    baseURL := "https://www.{instance}.service-now.com/api/now"

    // Implement your credential and client.
    client := // Your client setup here
...

[DELETE] Remove Record

To remove a specific record from a table:

1. Fluent Interface Pattern

...
    
    // Optional Query Parameters
    params := &tableapi.TableItemRequestBuilderDeleteQueryParameters{
        // Define Query Parameters
    }

    // Execute the delete operation
    err := client.Now().Table2("{tableName}").ByID("{sysId}").Delete(params)
    if err != nil {
        panic(err)  // Error handling
    }
}

2. Building Request

Try on Playground

...
    // Specify the path parameters
    pathParameters := map[string]string{
        "baseurl": baseURL,
        "table":   "{tableName}", // Table name for the record
        "sysId":   "{sysId}", // Sys Id of the record
    }

    // Initialize a new request builder
    requestBuilder := tableapi.NewTableItemRequestBuilder2(client, pathParameters)

    // Optional Query Parameters
    params := &tableapi.TableItemRequestBuilderDeleteQueryParameters{
        // Define Query Parameters
    }

    // Execute the delete operation
    err := requestBuilder.Delete(params)
    if err != nil {
        panic(err) // Error handling
    }
}

[GET] Retrieve Records

To fetch multiple records from a table:

1. Fluent Interface Pattern

...

    // Optional Query Parameters
    params := &tableapi.TableRequestBuilderGetQueryParameters{
        // Define Query Parameters
    }

    // Execute the retrieval operation
    response, err := client.Now().Table2("{tableName}").Get(params)
    if err != nil {
        panic(err) // Error handling
    }
}

2. Building Request

Try on Playground

...
    // Specify the path parameters
    pathParameters := map[string]string{
        "baseurl": baseURL,
        "table":   "{tableName}", // Table name for the records
    }

    // Initialize a new request builder
    requestBuilder := tableapi.NewTableRequestBuilder2(client, pathParameters)

    // Optional Query Parameters
    params := &tableapi.TableRequestBuilderGetQueryParameters{
        // Define Query Parameters
    }

    // Execute the retrieval operation
    response, err := requestBuilder.Get(params)
    if err != nil {
        panic(err)  // Error handling
    }
}

[GET] Retrieve Record

This method retrieves a specific record identified by its sys_id from a specified table.

1. Fluent Interface Pattern

...

    // Optional Query Parameters
    params := &tableapi.TableItemRequestBuilderGetQueryParameters{
        // Define Query Parameters
    }

    // Execute the retrieval operation
    record, err := client.Now().Table2("{tableName}")ByID("{sysId}").Get()
    if err != nil {
        panic(err) // Error handling
    }
}

2. Building Request

Try on Playground

...
    // Specify the path parameters
    pathParameters := map[string]string{
        "baseurl": baseURL,
        "table":   "{tableName}", // Table name for the record
        "sysId":   "{sysId}", // Sys Id of the record
    }

    // Create a new TableItemRequestBuilder with your client and path parameters.
    requestBuilder := tableapi.NewTableItemRequestBuilder2(client, pathParameters)

    // Optional Query Parameters
    params := &tableapi.TableItemRequestBuilderGetQueryParameters{
        // Define Query Parameters
    }

    // Execute the retrieval operation.
    record, err := requestBuilder.Get(params)
    if err != nil {
        panic(err) // Error handling
    }
}

[POST] Create a Record

This method inserts a new record into a specified table.

Note: that this method does not support the insertion of multiple records.

1. Fluent Interface Pattern

...
    // Define the data for the new record
    data := map[string]string{
        "short_description": "example incident",
        "description":       "incident created by servicenow-sdk-go",
    }

    // Optional Query Parameters
    param := &tableapi.TableRequestBuilderPostQueryParameters{
        // Define Query Parameters
    }

    // Execute the creation operation.
    response, err := client.Now().Table2("{tableName}").Post(data, param)
    if err != nil {
        panic(err) // Error handling
    }
}

2. Building Request

Try on Playground

...
    // Specify the path parameters
    pathParameters := map[string]string{
        "baseurl": baseURL,
        "table":   "{tableName}", // Table name for the record
    }

    // Define the data for the new record
    data := map[string]string{
        "short_description": "example incident",
        "description":       "incident created by servicenow-sdk-go",
    }

    // Create a new TableRequestBuilder with your client and path parameters.
    requestBuilder := tableapi.NewTableRequestBuilder2(client, pathParameters)

    // Optional Query Parameters
    param := &tableapi.TableRequestBuilderPostQueryParameters{
        // Define Query Parameters
    }

    // Execute the creation operation.
    response, err := requestBuilder.Post(data, param)
    if err != nil {
        panic(err) // Error handling
    }
}

[PUT] Update a Record

Update one record in the specified table.

Note: Make sure only the fields you intend on updating are included

1. Fluent Interface Pattern

...

    // Define the data for the new record
    data := map[string]string{
        "short_description": "example incident",
        "description": "incident created by servicenow-sdk-go",
    }

    // Optional query parameters
    params := &tableapi.TableItemRequestBuilderPutQueryParameters{
        // Define Query Parameters
    }

    // Execute the update operation.
    response, err := client.Now().Table2("{tableName}").ByID("{sysID}").Put(data, params)
    if err != nil {
        panic(err) // Error handling
    }
}

2. Building Request

Try on Playground

...

    // Specify the path parameters
    pathParameters := {
        "baseurl": baseURL,
        "table": "{tableName}",
        "sysId": "{sysID}",
    }

    // Define the data for the new record
    data := map[string]string{
        "short_description": "example incident",
        "description": "incident created by servicenow-sdk-go",
    }

    // Create a new TableRequestBuilder with your client and path parameters.
    requestBuilder := tableapi.NewTableItemRequestBuilder2(client, pathParameters)

    // Optional query parameters
    params := &tableapi.TableItemRequestBuilderPutQueryParameters{
        // Define Query Parameters
    }

    // Execute the update operation.
    response, err := requestBuilder.Put(data, params)
    if err != nil {
        panic(err) // Error handling
    }
}

# Functions

No description provided by the author
NewFragment creates a new query fragment with the specified field, operator, and value.
NewOrderBy Creates new order by.
Deprecated: deprecated in v1.5.0.
NewQuery returns a new Query with no conditions.
NewTableEntry creates a new table entry instance.
Deprecated: deprecated since v{unreleased}.
NewTablePageIterator is a function that creates a new instance of TablePageIterator.
Deprecated: deprecated since v{unreleased}.

# Constants

Deprecated: deprecated since v{unreleased}.
And ..
Asc ..
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since v{unreleased}.
Deprecated: deprecated since 1.4.0.
Desc ..
Deprecated: deprecated since v{unreleased}.
DisplayValueAll Returns both actual and display values.
DisplayValueFalse Returns the actual values from the database.
DisplayValueTrue Returns the display values for all fields.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since v{unreleased}.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since v{unreleased}.
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since 1.4.0.
Or ..
Deprecated: deprecated since 1.4.0.
Deprecated: deprecated since v{unreleased}.
Unset ..
ViewBoth Returns fields for both views.
No description provided by the author
ViewDesktop Returns fields for the desktop view.
No description provided by the author
ViewMobile Returns fields for the mobile view.
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Deprecated: deprecated in v1.5.0.
PageResult represents a single page of results from a table.
TableCollectionResponse2 represents a collection of table entries.
Deprecated: deprecated since v1.4.0.
Deprecated: deprecated since v1.4.0.
Deprecated: deprecated since v1.4.0.
Deprecated: deprecated since v1.4.0.
Deprecated: deprecated since v{unreleased}.
TableItemRequestBuilderDeleteQueryParameters represents DELETE query parameters for a Table Item Request.
TableItemRequestBuilderGetQueryParameters represents GET query parameters for a Table Item Request.
TableItemRequestBuilderPutQueryParameters represents PUT query parameters for a Table Item Request.
TableItemResponse2[T] represents a T Entry single table record response.
TablePageIterator is a generic struct in Golang which is used to iterate over pages of entries.
Deprecated: deprecated since v1.4.0.
TableRecordImpl is an implementation of TableRecord.
Deprecated: deprecated since v{unreleased}.
TableRequestBuilderGetQueryParameters represents GET query parameters for a Table Item Request.
TableRequestBuilderPostQueryParameters represents POST query parameters for a Table Item Request.
Deprecated: deprecated as of v1.4.0.
No description provided by the author
TableValue is the reflection interface to a table value.

# Interfaces

ElementValue represents a generic value.
Entry
No description provided by the author
RecordElement represents an element within a record.
No description provided by the author
TableItemRequestBuilder2 provides an interface for the service methods, adhering to the Interface Segregation Principle.
No description provided by the author
TableRecord represents a record with attributes.
TableRequestBuilder2 defines the operations available for the table as a whole.

# Type aliases

DisplayValue Determines the type of data returned, either the actual values from the database or the display values of the fields.
Fragment represents a query fragment with a field, operator, and value.
LogicalOperator ..
OrderBy represents an order-by clause.
OrderDirection represents the order direction for sorting.
Query represents a ServiceNow query and its conditions.
Deprecated: deprecated since 1.4.0.
TableEntry represents a single Service-Now Table Entry.
View UI view for which to render the data.
No description provided by the author