---
sourceDocument: Xanadu API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# CatalogItemVariableSet - スコープ指定

# CatalogItemVariableSet - スコープ指定 {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：7分

CatalogItemVariableSet API は、スクリプトを使用してサービスカタログアイテム変数セットを作成および変更できるメソッドを提供します。

この API は `sn_sc` 名前空間で実行されます。

## CatalogItemVariableSet - create(ブール standardUpdate) {#ariaid-title2}

定義されたカタログアイテム変数セットを挿入します。
{#r_CatalogItemVariableSet-create_Boolean__table_dk2_55d_ns__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| standardUpdate | ブーリアン | エンジンとワークフローの実行を有効にするかどうかを示すフラグです。 有効な値： * true：エンジンとワークフローの実行を有効にします。 * false：エンジンとワークフローの実行を有効にしません。 {#r_CatalogItemVariableSet-create_Boolean__ul_ygw_ztp_lnb} |
[表 : 1. パラメーター]

{#r_CatalogItemVariableSet-create_Boolean__table_dk2_55d_ns} {#r_CatalogItemVariableSet-create_Boolean__table_ek2_55d_ns__entry__2}

| タイプ | 説明 |
|-|-|
| 文字列 | 挿入された変数レコードの sys_id です。 |
[表 : 2. 返される内容]

{#r_CatalogItemVariableSet-create_Boolean__table_ek2_55d_ns}  

    // Given an existing catalog item
    var catItemSysId = "e0d08b13c3330100c8b837659bba8fb4";
    addVariableSets(catItemSysId);

    function addVariableSets(catItemSysId) {
      // List of all variable sets to attach
      var myVarSets = [];

      // Create variable set
      var myVarSetAttrs = {"name": "Requester details", "order": "100"};
      var myVarSet = new sn_sc.CatalogItemVariableSet();
      myVarSet.setAttributes(myVarSetAttrs);
      var myVarSetId = myVarSet.create(true);
      myVarSets.push(myVarSetId);
    }

## CatalogItemVariableSet - deleteRecord(ブール standardUpdate) {#ariaid-title3}

変数セットを削除します。
{#r_CatalogItemVariableSet-deleteRecord_Boolean__table_rzk_z5d_ns__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| standardUpdate | ブーリアン | エンジンとワークフローの実行を有効にするかどうかを示すフラグです。 有効な値： * true：エンジンとワークフローを有効にします。 * false：エンジンとワークフローを有効にしません。 {#r_CatalogItemVariableSet-deleteRecord_Boolean__ul_nnx_xwn_kpb} |
[表 : 3. パラメーター]

{#r_CatalogItemVariableSet-deleteRecord_Boolean__table_rzk_z5d_ns} {#r_CatalogItemVariableSet-deleteRecord_Boolean__table_szk_z5d_ns__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 4. 返される内容]

{#r_CatalogItemVariableSet-deleteRecord_Boolean__table_szk_z5d_ns}  
この例は、My Variable Set を使用しているすべてのカタログアイテムから My Variable Set を削除して、My Variable Set レコードを削除します。

    // Get the sys_id of the variable set you want to delete
    var vSet = new GlideRecord('item_option_new_set');
    vSet.addEncodedQuery('title=My Variable Set'); // find My Variable Set
    vSet.query();
    if (vSet.next()) {

        // first remove the variable set from all catalog items
        var catItemVset = new GlideRecord('io_set_item'); // M2M table linking variable set and catalog item
        catItemVset.addQuery('variable_set', vSet.getUniqueValue); // find all catalog items using My Variable Set
        catItemVset.query();
        while (catItemVset.next()) {
            var vsetM2M = new sn_sc.CatalogItemVariableSetM2M(catItemVset.getUniqueValue()); // io_set_item M2M record sys_id
            vsetM2M.deleteRecord(true); // delete M2M record
        }

        // then delete the variable set record
        var varset = new sn_sc.CatalogItemVariableSet(vSet.getUniqueValue()); 
        varset.deleteRecord(true);
    }

## CatalogItemVariableSet - read(オブジェクト columns, ブール standardUpdate) {#ariaid-title4}

カタログアイテム変数セットの属性値のマッピングを返します。
{#r_CatalogItemVariableSet-read_Object_Boolean__table_k4p_dvd_ns__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| 列 | オブジェクト | 値を希望する列のセットを指定します。 |
| standardUpdate | ブーリアン | エンジンとワークフローの実行を有効にするかどうかを示すフラグです。 有効な値： * true：エンジンとワークフローを有効にします。 * false：エンジンとワークフローを有効にしません。 {#r_CatalogItemVariableSet-read_Object_Boolean__ul_nnx_xwn_kpb} |
[表 : 5. パラメーター]

{#r_CatalogItemVariableSet-read_Object_Boolean__table_k4p_dvd_ns} {#r_CatalogItemVariableSet-read_Object_Boolean__table_l4p_dvd_ns__entry__2}

| タイプ | 説明 |
|-|-|
| オブジェクト | 列名を値にマッピングするオブジェクトです。 |
[表 : 6. 返される内容]

{#r_CatalogItemVariableSet-read_Object_Boolean__table_l4p_dvd_ns}

## CatalogItemVariableSet - setAttributes(オブジェクト attributes) {#ariaid-title5}

変数セットの属性を設定します。
{#r_CatalogItemVariableSet-setAttributes_Map__table_urd_nvd_ns__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| 属性 | オブジェクト | 列名を値にマッピングするオブジェクト |
[表 : 7. パラメーター]

{#r_CatalogItemVariableSet-setAttributes_Map__table_urd_nvd_ns} {#r_CatalogItemVariableSet-setAttributes_Map__table_vrd_nvd_ns__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 8. 返される内容]

{#r_CatalogItemVariableSet-setAttributes_Map__table_vrd_nvd_ns}  
この例は、変数セットを作成して、新しい変数セットに変数を追加します。

    createVariableSet('My Variable Set', 'This is my test variable set', '100', 'one_to_one');

    function createVariableSet(name, description, order, type) {
        var myVarSet = new sn_sc.CatalogItemVariableSet();
        // fields used in object are from table item_option_new_set
        var myVarSetAttrs = {
            "name": name,
            "description": description,
            "order": order,
            "type": type
        }; 
        myVarSet.setAttributes(myVarSetAttrs);
        var myVarSetId = myVarSet.create(true); // returns the sys_id of the created variable set
        gs.info('Variable set created in table item_option_new_set with sys_id ' + myVarSetId);

        // add a variable to the newly created variable set
        var myVar = new sn_sc.CatalogItemVariable();
        var myVarAttrs = {
            "type": "6", // type 6 is single line text
            "variable_set": myVarSetId.toString(), 
            "question_text": "Example question",
            "name": "example_question",
            "order": 200
        };
        myVar.setAttributes(myVarAttrs);
        myVar.create(true);
    }

出力:

    Variable set created in table item_option_new_set with sys_id e21df65a1bff7c10593876a61a4bcbc4

## CatalogItemVariableSet - update(オブジェクト columnValues, ブール standardUpdate) {#ariaid-title6}

変数セットを更新します。
{#r_CatalogItemVariableSet-update_Object_Boolean__table_z35_5vd_ns__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| columnValues | オブジェクト | 列名を値にマッピングするオブジェクト |
| standardUpdate | ブーリアン | エンジンとワークフローの実行を有効にするかどうかを示すフラグです。 有効な値： * true：エンジンとワークフローを有効にします。 * false：エンジンとワークフローを有効にしません。 {#r_CatalogItemVariableSet-update_Object_Boolean__ul_nnx_xwn_kpb} |
[表 : 9. パラメーター]

{#r_CatalogItemVariableSet-update_Object_Boolean__table_z35_5vd_ns} {#r_CatalogItemVariableSet-update_Object_Boolean__table_aj5_5vd_ns__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 10. 返される内容]

{#r_CatalogItemVariableSet-update_Object_Boolean__table_aj5_5vd_ns}  
この例は、Standard Employee Questions 変数セットの説明と順序を更新します。

    // Get the sys_id of the variable set you want to update
    var vSet = new GlideRecord('item_option_new_set');
    vSet.addEncodedQuery('title=Standard Employee Questions'); // find the Standard Employee Questions variable set
    vSet.query();
    if (vSet.next()) {
        var varset = new sn_sc.CatalogItemVariableSet(vSet.getUniqueValue()); 
        var attr = {
            'description': 'This should be used for all end user requests such as phones, tablets, etc. \n My description line',
            'order': '500' 
        };
        varset.update(attr, true);
    }


