Skip to main content
Version: 4.5.0

Function: Record(record)

Create a record in any table. This is a low-level function typically used as a fallback when the specific record type or metadata does not have its own dedicated API. When possible, prefer using other, dedicated APIs to generate metadata as those APIs will often have better type safety and will be easier to use.

Parameters

record

object

an object containing the following properties:

Properties:

  • $id (required): string | number | ExplicitKey<string>

  • data (required): Data<keyof Tables> Fields and their values in the table.

  • table (required): keyof Tables The table to which the record belongs.

  • $meta (optional): object

    • installMethod: 'first install' | 'demo' Map a record to an output folder that loads only in specific circumstances. 'first install' - > 'unload', 'demo' -> 'unload.demo'

See

Examples

Custom Table Record that extends sys_metadata

Create a record in a custom application table that extends sys_metadata.

/**
* @title Custom Table Record that extends sys_metadata
* @description Create a record in a custom application table that extends sys_metadata.
* This table has 3 fields (string_field: string, datetime_field: datetime, integer_field: integer) in addition to the fields inherited from sys_metadata.
*/
import { Record } from "@servicenow/sdk/core";

Record({
table: "x_helloworld_tableone",
$id: Now.ID["x_helloworld_tableone_record1"],
data: {
string_field: "Hello World 1",
datetime_field: "01-01-2024 12:00:00",
integer_field: 1,
},
});

Record example for populating demo data

For defining demo data in your application, some APIs expose the $meta: { installMethod } property

/**
* @title Record example for populating demo data
* @description For defining demo data in your application, some APIs expose the `$meta: { installMethod }` property
* which allows you to specify a record that should be created during installation of your application.
* This example shows how to use the `Record` function to create a record in the `incident` table, and
* install the record when the "Load demo data" option is selected during installation
*/
import { Record } from '@servicenow/sdk/core'
Record({
$id: Now.ID['incident-1'],
table: 'incident',
data: {
number: 'INC0010001',
active: true,
short_description: 'This is a sample incident',
description: 'This is a sample incident description',
comments: 'This is a sample comment',
urgency: 1,
approval: 'not requested',
notify: 1,
priority: 3,
$meta: {
installMethod: 'demo'
}
},
})

Adds a Record to an Out-of-Box Table (user_criteria)

Create a record in the user_criteria table, which is an out-of-box table in ServiceNow.

/**
* @title Adds a Record to an Out-of-Box Table (`user_criteria`)
* @description Create a record in the `user_criteria` table, which is an out-of-box table in ServiceNow.
*/
import { Record } from "@servicenow/sdk/core";

Record({
table: "user_criteria",
$id: Now.ID["user_criteria_example_1"],
data: {
name: "All ACME Corporation employees",
short_description: "Criteria for all ACME Corporation employees",
active: true,
advanced: false,
match_all: false,
company: [
"e7c1f3d53790200044e0bfc8bcbe5deb",
"227cdfb03710200044e0bfc8bcbe5d6b",
],
},
});