レコード API - ServiceNow Fluent

  • リリースバージョン: Zurich
  • 更新日 2025年07月31日
  • 所要時間:4分
  • レコード API は、任意のテーブルのレコードを定義します。レコード API を使用して、専用の ServiceNow Fluent API を持たないアプリケーションメタデータを定義します。

    Record オブジェクト

    レコードのあるテーブルにデータを追加します。

    表 : 1. プロパティ
    名前 タイプ 説明
    $id 文字列または数値 必須。メタデータオブジェクトの一意の ID。アプリケーションをビルドすると、この ID は一意のsys_idにハッシュされます。詳細については、「ServiceNow Fluent 言語構成」を参照してください。

    形式: Now.ID['string' or number]

    table 文字列 必須。レコードが属するテーブルの名前。
    データ オブジェクト テーブル内のフィールドとその値。たとえば、次のようになります。
    data: {
       state: 'Ready',
       task: 'Add demo data'
    }
    別のファイルのテキストコンテンツを使用するには、 Now.include 構文を使用してアプリケーション内のファイルを参照します。詳細については、「ServiceNow Fluent 言語構成」を参照してください。
    data: {
       script: Now.include('./script-file.js'),
       html: Now.include('./html-file.html'),
       css: Now.include('./css-file.css')
     }
    $meta オブジェクト アプリケーションメタデータのメタデータ。
    installMethod プロパティを使用すると、特定の状況でのみロードされる出力ディレクトリにアプリケーションメタデータをマップできます。
    $meta: {
          installMethod: 'String'
    }
    installMethod の有効な値:
    • demo:[デモデータのロード] オプションが選択されている場合、アプリケーションメタデータを metadata/unload.demo ディレクトリに出力して、アプリケーションとともにインストールします。
    • 初回インストール:アプリケーションがインスタンスに初めてインストールされたときにのみインストールされるように 、アプリケーションメタデータをメタデータ/アンロード ディレクトリに出力します。
    この例では、メニューカテゴリを定義するレコードがメニューカテゴリ [sys_app_category] テーブルに追加されます。メニューカテゴリのスタイルは、 css-file.css ファイルで定義されます。
    import { Record } from "@servicenow/sdk/core";
    
    export const appCategory = Record({
       table: 'sys_app_category',
       $id: Now.ID[9],
       data: {
          name: 'example',
          style: Now.include('./css-file.css'),
       },
    })
    この例では、インシデントを定義するレコードがインシデント [incident] テーブルに追加されます。
    import { Record } from '@servicenow/sdk/core';
    
    export const incident1 = Record({
      $id: Now.ID['incident-1'],
      table: 'incident',
      data: {
        active: 'true',
        approval: 'not requested',
        description: 'Unable to send or receive emails.',
        incidentState: '1',
        shortDescription: 'Email server is down.',
        subcategory: 'email',
        callerId: '77ad8176731313005754660c4cf6a7de',
      }
    })
    この例では、サーバーを定義するレコードがサーバー [cmdb_ci_server] テーブルに追加されます。
    import { Record } from '@servicenow/sdk/core';
    
    export const ciserver1 = Record({
      $id: Now.ID['cmdb-ci-server-1'],
      table: 'cmdb_ci_server',
      data: {
        assetTag: 'P1000199',
        attested: 'false',
        canPrint: 'false',
        company: 'e7c1f3d53790200044e0bfc8bcbe5deb',
        cost: '2160',
        costCc: 'USD',
        cpuSpeed: '633',
        cpuType: 'GenuineIntel',
        diskSpace: '100',
        manufacturer: 'b7e7d7d8c0a8016900a5d7f291acce5c',
        name: 'DatabaseServer1',
        os: 'Linux Red Hat',
        shortDescription: 'DB Server',
        subcategory: 'Computer',
      }
    })