Skip to content

Create table record

Overview

Creates a single record in the specified table.

Note: This endpoint doesn't support bulk insertion.

Path parameters

Name Description
baseurl The absolute base URI for the request (this is the same for all requests) including: the schema, the domain, and a path fragment.
table The table name of for the operation.

Optional query parameters

Name Type Possible values Description
DisplayValue tableapi.DisplayValue2 DisplayValue2True, DisplayValue2False, or DisplayValue2All Determines the type of data returned, either the actual values from the database or the display values of the fields.
ExcludeReferenceLink bool N/A Flag that indicates whether to exclude Table API links for reference fields.
Fields []string N/A List of fields to include in the response.
InputDisplayValue bool N/A Flag that indicates whether to set field values using the display value or the actual value.
View tableapi.View2 View2Desktop, View2Mobile, or View2Both UI view for which to render the data.

Required query parameters

N/A

Examples

package main


import (
    "context"
    "fmt"
    "log"

    servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go"
    tableapi "github.com/michaeldcanady/servicenow-sdk-go/table-api"
)

func main() {
    // Step 1: Create credentials

    cred := credentials.NewBasicProvider("{username}", "{password}")


    // Step 2: Initialize client

    client, err := servicenowsdkgo.NewServiceNowServiceClient(
        servicenowsdkgo.WithAuthenticationProvider(cred),
        servicenowsdkgo.WithURL("https://{instance}.service-now.com"),
    )
    if err != nil {
        log.Fatal(err)
    }


    // Step 3: Configure request
    createConfig := &tableapi.TableRequestBuilder2PostRequestConfiguration{
        QueryParameters: &tableapi.TableRequestBuilder2PostQueryParameters{
            // Optional configurations
        },
    }

    // Step 4: Build request body
    createData := tableapi.NewTableRecord()
    if err := createData.SetValue("short_description", "example incident"); err != nil {
        log.Fatal(err)
    }
    if err := createData.SetValue("description", "incident created by servicenow-sdk-go"); err != nil {
        log.Fatal(err)
    }

    // Step 5: Execute request
    create_response, err := client.Now2().TableV2("{TableName}").Post(context.Background(), createData, createConfig)
    if err != nil {
        log.Fatal(err)
    }

}
package main


import (
    "context"
    "fmt"
    "log"

    servicenowsdkgo "github.com/michaeldcanady/servicenow-sdk-go"
    tableapi "github.com/michaeldcanady/servicenow-sdk-go/table-api"
)

func main() {
    // Step 1: Create credentials

    cred := credentials.NewBasicProvider("{username}", "{password}")


    // Step 2: Initialize client

    client, err := servicenowsdkgo.NewServiceNowServiceClient(
        servicenowsdkgo.WithAuthenticationProvider(cred),
        servicenowsdkgo.WithURL("https://{instance}.service-now.com"),
    )
    if err != nil {
        log.Fatal(err)
    }


    // Step 3: Define raw URL
    rawURL = "https://https://{instance}.service-now.com/api/now/v1/table/{TableName}"

    // Step 4: Build request
    collectionRequestBuilder = tableapi.NewDefaultTableRequestBuilder2(rawURL, client.RequestAdapter)


    // Step 5: Configure request
    createStdConfig := &tableapi.TableRequestBuilder2PostRequestConfiguration{
        QueryParameters: &tableapi.TableRequestBuilder2PostQueryParameters{
            // Optional configurations
        },
    }

    // Step 6: Build request body
    createStdData := tableapi.NewTableRecord()
    if err := createStdData.SetValue("short_description", "example incident"); err != nil {
        log.Fatal(err)
    }
    if err := createStdData.SetValue("description", "incident created by servicenow-sdk-go"); err != nil {
        log.Fatal(err)
    }

    // Step 7: Execute request
    create_std_response, err := collectionRequestBuilder.Post(context.Background(), createStdData, createStdConfig)
    if err != nil {
        log.Fatal(err)
    }

}