CatItem - 범위 지정됨
CatItem API는 스크립트를 사용하여 서비스 카탈로그 항목을 생성하고 수정할 수 있는 메서드를 제공합니다.
이 API는 sn_sc 네임스페이스에서 실행됩니다.
CatItem - availableForUserCriteria(문자열 작업, 배열 criteriaIDs)
현재 카탈로그 항목에 사용자 기준을 추가합니다 Available For .
| 이름 | 유형 | 설명 |
|---|---|---|
| 작업 | 문자열 | 수행할 작업입니다.
|
| criteriaID | 배열 | 사용자 기준 sys_ids의 배열입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예시에서는 지정된 Available For 사용자 기준을 추가하는 방법을 보여줍니다.
var item = new sn_sc.CatItem("31bea3d53790200044e0bfc8bcbe5dec");
item.availableForUserCriteria("add", ["0c441abbc6112275000025157c651c89"]);
카탈로그 항목 - canViewInDomain()
선택한 도메인(도메인 선택기에서 선택한 도메인)에서 현재 카탈로그 항목을 볼 수 있는지 확인합니다.
전역 도메인의 카탈로그 항목은 모든 도메인에서 사용할 수 있습니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 | 선택한 도메인에서 현재 카탈로그 항목을 볼 수 있는지 여부를 확인하는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 예시에서는 현재 선택한 도메인에서 카탈로그 항목을 볼 수 있는지 여부를 확인하는 방법을 보여줍니다.
var catItem = new sn_sc.CatItem("060f3afa3731300054b6a3549dbe5d3e");
gs.info(catItem.canViewInDomain());
CatItem - canViewOnSearch(boolean isMobile)
사용자가 전역 검색에서 카탈로그 항목을 볼 수 있는 액세스 권한이 있는지 여부를 결정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| isMobile | 부울 | 모바일 뷰 또는 데스크톱 뷰 검색을 수행할지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
| 유형 | 설명 |
|---|---|
| 부울 | 사용자가 전역 검색에서 카탈로그 항목을 볼 수 있는 액세스 권한이 있는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 코드 예제에서는 사용자가 데스크톱 보기의 전역 검색에서 카탈로그 항목을 볼 수 있는 액세스 권한이 있는지 확인하는 방법을 보여 줍니다.
var catItem = new sn_sc.CatItem("04b7e94b4f7b4200086eeed18110c7fd");
var canView = catItem.canViewOnSearch('false');
gs.info("Can view on global search: " + canView);
출력:
Can view on global search: true
CatItem - create(부울 standardUpdate)
정의된 카탈로그 항목을 삽입합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 표준 업데이트 | 부울 | 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
| 유형 | 설명 |
|---|---|
| 문자열 | 새로 만든 카탈로그 항목의 Sys_id입니다. |
이 예시에서는 새 카탈로그 항목을 만들고 변수와 변수 세트를 추가합니다.
createCatalogItem('Catalog Item Name', 'Short Description', 'e0d08b13c3330100c8b837659bba8fb4', '109f0438c6112276003ae8ac13e7009d');
function createCatalogItem(name, short_desc, catalogId, categoryId) {
var catalogItem = new sn_sc.CatItem();
catalogItem.setAttributes({
"name": name,
"short_description": short_desc
});
catalogItem.setCatalogs(catalogId); // set catalog
catalogItem.setCategories(categoryId); // set category
var catItemSysId = catalogItem.create(); // create new catalog item
gs.info('Catalog item created in table sc_cat_item with sys_id ' + catItemSysId);
// add variables and variable set
addDefaultVariables(catItemSysId);
addDefaultVariableSet(catItemSysId);
}
// creates a new variable and adds it to the catalog item
function addDefaultVariables(catItemSysId) {
var myVarAttrs = {
"type": "6", // type 6 is single line text
"cat_item": catItemSysId,
"question_text": "First Name",
"name": "first_name",
'order': 50
};
var myVar = new sn_sc.CatalogItemVariable();
myVar.setAttributes(myVarAttrs);
var varRec = myVar.create(true);
gs.info('Variable added to catalog item and record created in table item_option_new with sys_id ' + varRec);
}
// adds an existing variable set to the catalog item
function addDefaultVariableSet(catItemSysId) {
var varset = new sn_sc.CatalogItemVariableSetM2M();
// fields used in object are from table io_set_item
var attr = {
'variable_set': 'e01cab1a4f334200086eeed18110c71f', // required
'sc_cat_item': catItemSysId, // required
'order': 100 // 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);
}
출력:
Catalog item created in table sc_cat_item with sys_id be5c771e876370103a730f2d0ebb3556
Variable added to catalog item and record created in table item_option_new with sys_id b65cb71e876370103a730f2d0ebb3535
Variable set added to catalog item and M2M record created in table io_set_item with sys_id 8b5cb71e876370103a730f2d0ebb354b
CatItem - deleteRecord(부울 standardUpdate)
카탈로그 항목을 삭제합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 표준 업데이트 | 부울 | 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
| 유형 | 설명 |
|---|---|
| void |
이 예에서는 모든 비활성 카탈로그 항목을 삭제합니다.
var catalogItem = new GlideRecord('sc_cat_item');
catalogItem.addQuery('active', 'false'); // get all inactive catalog items
catalogItem.query();
while (catalogItem.next()) {
// before deleting a catalog item, delete its associated variable set M2M records
var variableSetM2M = new GlideRecord('io_set_item'); // M2M table linking variable set and catalog item
variableSetM2M.addQuery('sc_cat_item', catalogItem.getUniqueValue()); // get M2M records for the catalog item
variableSetM2M.query();
while (variableSetM2M.next()) {
var varset = new sn_sc.CatalogItemVariableSetM2M(variableSetM2M.getUniqueValue()); // M2M record sys_id
varset.deleteRecord(true); // delete M2M record
}
// then delete the catalog item
var item = new sn_sc.CatItem(catalogItem.getUniqueValue());
item.deleteRecord(true);
}
CatItem - getFirstAccessibleCategoryForSearch(문자열 catalogId)
사용자가 카탈로그에서 볼 수 있는 첫 번째 범주를 반환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 카탈로그 ID | 문자열 | 카탈로그의 Sys_id입니다. |
| 유형 | 설명 |
|---|---|
| 문자열 | 사용자가 카탈로그에서 볼 수 있는 첫 번째 범주의 Sys_id입니다. |
예제:
var CatItem=new sn_sc.CatItem("04b7e94b4f7b4200086eeed18110c7fd");
console.log(CatItem.getFirstAccessibleCategoryForSearch("e0d08b13c3330100c8b837659bba8fb4"));
출력:
d258b953c611227a0146101fb1be7c31
CatItem - getInvalidDelegatedUsers(array: requestForUsers)
연결된 항목을 위임(대신 요청)할 수 없는 사용자의 배열을 반환합니다.
이 메서드는 배열에 전달된 각 사용자를 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| requestForUsers | 객체 | 연결된 사용자가 현재 항목을 획득할 수 있는지, 그리고 자신을 대신하여 항목을 요청할 수 있는지 여부를 확인하기 위한 사용자 sys_ids 배열입니다. 테이블: 사용자 [sys_user] |
| 유형 | 설명 |
|---|---|
| 배열 | 대리인이 항목을 요청할 수 없는 사용자 이름 목록(사용자 [sys_user] 테이블의 이름 열)입니다. |
이 예제에서는 대리인이 항목을 요청할 수 없는 사용자 이름 목록을 가져오는 방법을 보여 줍니다.
function getInvalidDelegatedUsers(itemId, userIds) {
var catItem = new sn_sc.CatItem(itemId);
var invalidUsers = catItem.getInvalidDelegatedUsers(userIds);
return invalidUsers;
}
출력:
[
"Joe Smith",
"Jenny Brown",
"Fred Bennet",
"Alice Jones"
]
CatItem - getRecordClass()
현재 카탈로그 항목 기록의 클래스 이름을 반환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 문자열 | 현재 카탈로그 항목 기록의 클래스 이름입니다. |
예제:
var CatItem=new sn_sc.CatItem("04b7e94b4f7b4200086eeed18110c7fd");
console.log(CatItem.getRecordClass());
출력:
sc_cat_item
CatItem - isDelegationAllowed(String delegatedUser)
지정된 위임된 사용자에게 현재 서비스 카탈로그 항목에 대한 취득 권한이 있는지 확인합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 위임된 사용자 | 문자열 | 옵션입니다. 서비스 카탈로그 항목을 요청할 사용자의 Sys_id(위임자)입니다. 이 메서드는 사용자에게 항목에 대한 취득 권한이 있는지 확인합니다. 기본값: 호출하는 사용자에게 항목에 대한 취득 권한이 있는지 확인합니다. |
| 유형 | 설명 |
|---|---|
| 부울 | 사용자에게 현재 서비스 카탈로그 항목에 대한 획득 권한이 있는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
이 코드 예제에서는 카탈로그 항목에 대해 위임이 허용되는지 여부를 결정하는 방법을 보여 줍니다.
function canRequestFor(itemId, user) {
var catItem = new sn_sc.CatItem(itemId);
var result = catItem.isDelegationAllowed(user);
return result;
}
출력: true
CatItem - isVisibleServicePortal()
현재 카탈로그 항목을 서비스 포털에서 사용할 수 있는지 여부를 결정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 없음 |
| 유형 | 설명 |
|---|---|
| 부울 | Service Portal에서 카탈로그 항목을 사용할 수 있는지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
예제:
var catItem = new sn_sc.CatItem("04b7e94b4f7b4200086eeed18110c7fd");
var catItemAvail = catItem.isVisibleServicePortal();
gs.info("Is item available on Service Portal: " + catItemAvail);
출력:
Is item available on Service Portal: true
CatItem - notAvailableForUserCriteria(문자열 작업, 배열 criteriaIDs)
카탈로그 항목에 사용자 기준을 추가합니다 Not Available For .
| 이름 | 유형 | 설명 |
|---|---|---|
| 작업 | 문자열 | 수행할 작업입니다.
|
| 유형 | 설명 |
|---|---|
| void |
이 예시에서는 지정된 Not Available For 사용자 기준을 추가하는 방법을 보여줍니다.
var item = new sn_sc.CatItem("31bea3d53790200044e0bfc8bcbe5dec");
item. notAvailableForUserCriteria("add", ["0c441abbc6112275000025157c651c89"]);
CatItem - 읽기(객체 열, 부울 standardUpdate)
카탈로그 항목 속성 값의 매핑을 반환합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 열 | 객체 | 값을 반환할 열의 이름-값 쌍입니다. |
| 표준 업데이트 | 부울 | 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
| 유형 | 설명 |
|---|---|
| 객체 | 열 이름을 값에 매핑합니다. |
이 예시에서는 카탈로그 항목의 이름 및 가격 필드를 읽습니다.
var catItem = new sn_sc.CatItem("a96277509f300200b407b89a442e704e");
var values = catItem.read({"name" : "", "price" : ""}, true);
gs.info("Catalog item name: " + values.name);
gs.info("Catalog item price: " + values.price);
Catalog item name: Standard Laptop
Catalog item price: 1100CatItem - setAttributes(객체 속성)
카탈로그 항목의 속성을 설정합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 속성 | 객체 | 설정할 열의 이름-값 쌍입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예시에서는 새 카탈로그 항목의 속성을 설정합니다.
createCatalogItem('Name of your Catalog Item', 'Short Description of your Catalog Item', 'e0d08b13c3330100c8b837659bba8fb4', '109f0438c6112276003ae8ac13e7009d');
function createCatalogItem(name, short_desc, catalogId, categoryId) {
var catalogItem = new sn_sc.CatItem();
// catalog item column values
var attributes ={
"name": name,
"short_description": short_desc,
"description": "<p>This is a test catalog item.</p>",
"workflow":"0287f2c64a36232700820846b1f8bdce" // sys_id of workflow
};
catalogItem.setAttributes(attributes); // set catalog item attributes
catalogItem.setCatalogs(catalogId); // set catalog
catalogItem.setCategories(categoryId); // set category
var catItemSysId = catalogItem.create(); // create new catalog item
gs.info('Catalog item created in table sc_cat_item with sys_id ' + catItemSysId);
}
출력:
Catalog item created in table sc_cat_item with sys_id 706948a287e370103a730f2d0ebb351e
CatItem - setCatalogs(문자열 카탈로그)
이 카탈로그 항목과 관련된 카탈로그를 정의합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| catalogs | 문자열 | 항목과 연결할 카탈로그의 sys_ids 쉼표로 구분된 목록입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예시에서는 카탈로그 항목을 두 개의 카탈로그와 연결합니다.
var short_desc = 'This is a short description of my catalog item.';
var catalogItem = new sn_sc.CatItem();
catalogItem.setAttributes({
"name": 'My Catalog Item',
"short_description": short_desc
});
catalogItem.setCatalogs('e0d08b13c3330100c8b837659bba8fb4,742ce428d7211100f2d224837e61036d'); // set Service Catalog and Technical Catalog
var catItemSysId = catalogItem.create(); // create new catalog item
gs.info('Catalog item created in table sc_cat_item with sys_id ' + catItemSysId);
Catalog item created in table sc_cat_item with sys_id d0c5dcaa872770103a730f2d0ebb35cbCatItem - setCategories(String 범주)
이 카탈로그 항목과 관련된 범주를 정의합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| categories | 문자열 | 항목과 연결할 범주의 sys_ids 쉼표로 구분된 목록입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예시에서는 두 범주를 항목에 연결하는 방법을 보여줍니다.
var catItem = new sn_sc.CatItem("060f3afa3731300054b6a3549dbe5d3e");
catItem.setCatagories("af443cfa5f130100a9ad2572f2b47747", "d467125fd7500200d74460affd6103a1");
CatItem - setImage(문자열, dbImageSysId, 문자열 유형)
카탈로그 항목에 이미지를 추가합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| dbImageSysId | 문자열 | 이미지 테이블 [db_image]의 이미지 Sys_id입니다. |
| 유형 | 문자열 | 이미지의 유형입니다. 유효한 값은 다음과 같습니다.
|
| 유형 | 설명 |
|---|---|
| void |
이 예시에서는 카탈로그 항목에 이미지를 추가합니다.
var catItem = new sn_sc.CatItem("1fc0bd968777301093d5ec6d0ebb3548"); // sys_id of catalog item to update
// update fields if needed
var attr = {
'name': 'New Name of Catalog Item - 123',
'description': '<p>This is an updated description.</p><p> My description new line 1</p><p>My description new line 2</p>',
'short_description': 'New Short Description of Catalog Item'
};
catItem.update(attr, true);
catItem.setImage('1b443cfa5f130100a9ad2572f2b47746', 'picture'); // sys_id of image from table db_image
CatItem - setTableName(문자열 테이블 이름)
이 카탈로그 항목의 테이블 이름을 정의합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| tableName | 문자열 | 카탈로그 항목 [sc_cat_item]을 확장하는 테이블의 이름입니다. |
| 유형 | 설명 |
|---|---|
| void |
이 예에서는 확장 테이블의 이름을 설정하는 방법을 보여줍니다.
var catItem = new sn_sc.CatItem();
catItem.setTableName("New_catalog_table");
CatItem - submitProducer(객체 값)
지정된 서비스 카탈로그 기록 생성자를 사용하여 기록을 작성합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 값 | 객체 | 기록을 만들 때 사용할 필드 값과 기록 생성자가 포함됩니다. |
| values.variables | 객체 | 새 기록에 대해 설정할 필드 값입니다. |
| values.sysparm_id | 문자열 | 기록 생성자 [sc_cat_item_producer] 테이블에서 사용할 기록 생성자의 Sys_id. |
| 유형 | 설명 |
|---|---|
| 객체 | 생성된 레코드에 대한 정보를 포함합니다. |
| <Object>.수 | 생성된 기록의 번호 필드 값입니다. 데이터 유형: 문자열 |
| <Object>.parent_id | 상위 기록의 Sys_id입니다. 데이터 유형: 문자열 |
| <Object>.parent_table | 기록이 생성된 테이블의 상위 테이블입니다. 데이터 유형: 문자열 |
| <Object>.기록 | 생성된 기록의 XML입니다. 데이터 유형: 문자열 |
| <Object>.redirect_portal_url | 를 리디렉션할 URL입니다 서비스 포털. 데이터 유형: 문자열 |
| <Object>.redirect_to | 리디렉션 값입니다. 데이터 유형: 문자열 |
| <Object>.redirect_url | 생성된 기록의 URL입니다. 데이터 유형: 문자열 |
| <Object>.sys_id | 생성된 기록의 Sys_id입니다. 데이터 유형: 문자열 |
| <Object>.테이블 | 기록이 생성된 테이블입니다. 데이터 유형: 문자열 |
이 예에서는 인시던트 생성 기록 생성자를 사용하여 인시던트를 생성합니다.
var catalogItem = new sn_sc.CatItem('3f1dd0320a0a0b99000a53f7604a2ef9'); //sys_id of the Create Incident record producer
var values = {
"variables": {"urgency" : "2", "comments" : "Laptop is in a brick state"},
"sysparm_id": "3f1dd0320a0a0b99000a53f7604a2ef9"
}
var targetRecordDetails = catalogItem.submitProducer(values);
gs.info(JSON.stringify(targetRecordDetails, null, 3));
출력:
{
"sys_id": "133b2ee1875f30103a730f2d0ebb35f9",
"number": "INC0010002",
"parent_id": null,
"record": "api/now/table/incident/133b2ee1875f30103a730f2d0ebb35f9",
"redirect_portal_url": "",
"parent_table": "task",
"redirect_url": "incident.do?sys_id=133b2ee1875f30103a730f2d0ebb35f9&sysparm_view=ess",
"table": "incident",
"redirect_to": "generated_record"
}
CatItem - update(객체 columnValues, 부울 standardUpdate)
카탈로그 항목의 지정된 필드에 대한 값을 업데이트합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| columnValues | 객체 | 업데이트할 필드의 이름-값 쌍과 연결된 값입니다. |
| 표준 업데이트 | 부울 | 엔진과 워크플로우의 실행을 활성화할지 여부를 나타내는 플래그입니다. 유효한 값은 다음과 같습니다.
|
| 유형 | 설명 |
|---|---|
| void |
이 예제에서는 기존 카탈로그 항목의 이름, 짧은 설명 및 가격을 업데이트합니다.
var catItem = new sn_sc.CatItem("1fc0bd968777301093d5ec6d0ebb3548"); // sys_id of catalog item to update
printCatalogItem(); // print current catalog item values
// object containing fields to update
var attr = {
"name": "New Name of Catalog Item",
"short_description": "New Short Description of Catalog Item",
"price": "450"
};
catItem.update(attr, true);
printCatalogItem(); // print new catalog item values
// prints the name, short description, and price of the catalog item
function printCatalogItem(){
// object containing fields to read
var readValues = {
"name" : "",
"short_description" : "",
"price" : ""
};
var values = catItem.read(readValues, true); // read the field values
gs.info("Catalog item name: " + values.name);
gs.info("Catalog item short description: " + values.short_description);
gs.info("Catalog item price: " + values.price);
}
Catalog item name: Example Catalog Item
Catalog item short description: Example Short Description
Catalog item price: 300
Catalog item name: New Name of Catalog Item
Catalog item short description: New Short Description of Catalog Item
Catalog item price: 450