CatalogItemVariableSet - 범위 지정됨

  • 릴리스 버전: Washingtondc
  • 업데이트 날짜 2024년 02월 01일
  • 읽기7분
  • CatalogItem변수 세트 API를 사용하면 스크립트를 사용하여 Service Catalog 항목 변수 세트를 만들고 수정할 수 있습니다.

    CatalogItemVariableSet - create(부울 standardUpdate)

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

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

    변수 세트를 삭제합니다.

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

    이 예제에서는 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(객체 열, 부울 standardUpdate)

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

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

    CatalogItemVariableSet - setAttributes(attributes 객체)

    변수 세트의 속성을 설정합니다.

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

    이 예제에서는 변수 세트를 만든 다음 새 세트에 변수를 추가합니다.

    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)

    변수 세트를 업데이트합니다.

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

    이 예는 표준 직원 질문 변수 세트의 설명과 순서를 업데이트합니다.

    // 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);
    }