CatalogItemVariableSetM2M - 범위 지정됨

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기8분
  • CatalogItemVariableSetM2M API는 스크립트를 사용하여 서비스 카탈로그 항목 다대다(M2M)를 만들고 수정할 수 있는 메서드를 제공합니다.

    이 API는 sn_sc 네임스페이스에서 실행됩니다.

    카탈로그 항목 변수 세트M2M - 작성(부울 standardUpdate)

    정의된 카탈로그 항목 변수 세트 M2M을 삽입합니다.

    표 1. 매개변수
    이름 유형 설명
    표준 업데이트 부울 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다.
    유효한 값은 다음과 같습니다.
    • true: 엔진과 워크플로우를 활성화합니다.
    • false: 엔진과 워크플로우를 활성화하지 않습니다.
    표 2. 반환
    유형 설명
    문자열 삽입된 변수 기록의 Sys_id입니다.

    이 예에서는 표준 직원 질문 변수 세트를 iPhone 6s 카탈로그 항목에 추가하고 카탈로그 변수 세트 테이블 [io_set_item]에 연결하는 기록을 작성합니다.

    var cat_item_sys_id = 'bd6fa75a4f334200086eeed18110c79e'; // catalog item - iPhone 6s
    var variable_set_sys_id = 'e01cab1a4f334200086eeed18110c71f'; // variable set - Standard Employee Questions
    var app_scope = 'global'; // sys_id id in case of scoped app
    var varset = new sn_sc.CatalogItemVariableSetM2M();
    var attr = {
        'variable_set': variable_set_sys_id, // required
        'sc_cat_item': cat_item_sys_id, // required
        'sys_scope': app_scope, // optional
        'order': 10 // optional
    };
    varset.setAttributes(attr);
    var m2mRec = varset.create(true);
    gs.info('Variable set added to catalog item and M2M record created in table io_set_item with sys_id ' + m2mRec);

    출력:

    Variable set added to catalog item and M2M record created in table io_set_item with sys_id c5c87af187eb30103a730f2d0ebb3578

    카탈로그 항목변수세트M2M - deleteRecord(부울 standardUpdate)

    정의된 카탈로그 항목 변수 세트 M2M을 삭제합니다.

    표 3. 매개변수
    이름 유형 설명
    표준 업데이트 부울 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다.
    유효한 값은 다음과 같습니다.
    • true: 엔진과 워크플로우를 활성화합니다.
    • false: 엔진과 워크플로우를 활성화하지 않습니다.
    표 4. 반환
    유형 설명
    void

    이 예제에서는 표준 직원 질문 변수 세트를 iPhone 6s 카탈로그 항목에서 제거하고 카탈로그 변수 세트 테이블 [io_set_item]에 연결하는 기록을 삭제합니다.

    var vset = new GlideRecord('io_set_item');
    vset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s
    vset.addQuery('variable_set', 'e01cab1a4f334200086eeed18110c71f'); // variable set - Standard Employee Questions
    vset.query();
    if (vset.next()) {
        var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record
        varset.deleteRecord(true);  
    }

    CatalogItemVariableSetM2M - 읽기(객체 열, 부울 standardUpdate)

    카탈로그 항목 변수 세트 M2M 속성 값의 매핑을 반환합니다.

    표 5. 매개변수
    이름 유형 설명
    객체 값을 지정할 열 집합입니다.
    표준 업데이트 부울 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다.
    유효한 값은 다음과 같습니다.
    • true: 엔진과 워크플로우를 활성화합니다.
    • false: 엔진과 워크플로우를 활성화하지 않습니다.
    표 6. 반환
    유형 설명
    객체 열 이름을 값에 매핑하는 개체입니다.

    이 예시에서는 iPhone 6s 카탈로그 항목에 사용되는 모든 변수 세트를 읽습니다.

    var vset = new GlideRecord('io_set_item');
    vset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s
    vset.query();
    while (vset.next()) {
        var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record
        //add the fields you want to read from the record
        var attr = {
            'sys_name': '', // optional
            'sys_scope': '', // optional
            'order': '' // optional
        };
        var m2mRec = varset.read(attr, true);
        gs.info(JSON.stringify(m2mRec));
    }

    출력:

    {"sys_name":"HTML Description.iPhone 6s","sys_scope":"global","order":"10"}
    {"sys_name":"Standard Employee Questions.iPhone 6s","sys_scope":"global","order":"20"}
    

    카탈로그 항목변수세트M2M - setAttributes(객체 속성)

    이 카탈로그 항목 변수 세트 M2M에 대한 속성 값을 정의합니다.

    표 7. 매개변수
    이름 유형 설명
    속성 객체 열 이름을 값에 매핑하는 개체입니다.
    표 8. 반환
    유형 설명
    void

    이 예에서는 표준 직원 질문 변수 세트를 iPhone 6s 카탈로그 항목에 추가하고 카탈로그 변수 세트 테이블 [io_set_item]에 기록을 작성합니다.

    var cat_item_sys_id = 'bd6fa75a4f334200086eeed18110c79e'; // catalog item - iPhone 6s
    var variable_set_sys_id = 'e01cab1a4f334200086eeed18110c71f'; // variable set - Standard Employee Questions
    var app_scope = 'global'; // sys_id id in case of scoped app
    var varset = new sn_sc.CatalogItemVariableSetM2M();
    var attr = {
        'variable_set': variable_set_sys_id,
        'sc_cat_item': cat_item_sys_id,
        'sys_scope': app_scope,
        'order': 10
    };
    varset.setAttributes(attr);
    var m2mRec = varset.create(true);
    gs.info('Variable set added to catalog item and M2M record created in table io_set_item with sys_id ' + m2mRec);

    출력:

    Variable set added to catalog item and M2M record created in table io_set_item with sys_id c5c87af187eb30103a730f2d0ebb3578

    CatalogItemVariableSetM2M - update(객체 columnValues, 부울 standardUpdate)

    현재 카탈로그 항목 변수 세트 M2M을 세트 값으로 업데이트합니다.

    표 9. 매개변수
    이름 유형 설명
    columnValues 객체 열 이름을 값에 매핑하는 개체입니다.
    표준 업데이트 부울 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다.
    유효한 값은 다음과 같습니다.
    • true: 엔진과 워크플로우를 활성화합니다.
    • false: 엔진과 워크플로우를 활성화하지 않습니다.
    표 10. 반환
    유형 설명
    void

    이 예에서는 iPhone 6s 카탈로그 항목에 대한 표준 직원 질문 변수 세트의 순서를 업데이트합니다.

    var vset = new GlideRecord('io_set_item');
    vset.addQuery('sc_cat_item', 'bd6fa75a4f334200086eeed18110c79e'); // catalog item - iPhone 6s
    vset.addQuery('variable_set', 'e01cab1a4f334200086eeed18110c71f'); // variable set - Standard Employee Questions
    vset.query();
    if (vset.next()) {
        var varset = new sn_sc.CatalogItemVariableSetM2M(vset.getUniqueValue()); // pass sys_id of io_set_item record
        var attr = {
            'order': '30' // update order to 30
        };
        varset.update(attr, true);
        var readAttr = {
            'sys_name': '',
            'order': '' 
        };
        var m2mRec = varset.read(readAttr, true); // read the record to confirm the update 
        gs.info(JSON.stringify(m2mRec));
    }

    출력:

    {"sys_name":"Standard Employee Questions.iPhone 6s","order":"30"}