의 코드에서 ServiceNow Fluent 애플리케이션 메타데이터 정의 ServiceNow IDE

  • 릴리스 버전: Xanadu
  • 업데이트 날짜 2024년 08월 01일
  • 읽기6분
  • 을 사용하여 코드에서 애플리케이션 메타데이터 정의 ServiceNow FluentServiceNow IDE.

    시작하기 전에

    을 사용하여 범위가 지정된 애플리케이션을 생성하거나 복제합니다 ServiceNow IDE. 자세한 내용은 다음 를 사용하여 Git 리포지토리 복제 ServiceNow IDE문서를 참조하십시오를 사용하여 애플리케이션 생성 ServiceNow IDE.

    필요한 역할: admin

    이 태스크 정보

    ServiceNow Fluent 는 애플리케이션을 구성하는 메타데이터 파일[sys_metadata]을 정의하기 위한 TypeScript를 기반으로 하는 DSL(도메인별 언어)이며 테이블, 역할, ACL, 비즈니스 규칙 및 Automated Test Framework 테스트와 같은 다양한 유형의 메타데이터에 대한 API를 포함합니다. API 및 예제에 대한 ServiceNow Fluent 자세한 내용은 을 참조하십시오 ServiceNow Fluent API 참조.

    ServiceNow IDE.now.ts 파일에서 필수 속성 및 가져오기 확인을 포함하여 기본적으로 API에 대한 ServiceNow Fluent 언어 처리 및 유효성 검사가 있습니다.

    프로시저

    1. 다음으로 이동 모두 > ServiceNow IDE.
    2. 애플리케이션으로 작업 공간을 엽니다.
    3. 작업 표시줄에서 파일 탐색기 보기( 파일 탐색기)를 선택합니다.
    4. src/fluent 디렉터리에서 확장명이 .now.ts인 파일을 추가합니다.
      응용 프로그램 메타데이터를 단일 파일 또는 원하는 만큼 .now.ts 파일로 정의하고 fluent 디렉터리 내의 디렉터리에 파일을 구성할 수 있습니다.
      팁:
      fluent 디렉터리에서 index.now.ts라는 예제 파일을 참조할 수 있습니다.
    5. .now.ts 파일에서 API의 ServiceNow Fluent 개체를 사용하여 응용 프로그램의 메타데이터를 정의합니다.
      예를 들어 애플리케이션에서 테이블 [sys_db_object]을 만들려면 Table API를 사용합니다. 다음 예제에는 필요한 속성 및 값이 있는 Table 개체를 사용하는 할 일 목록에 대한 간단한 표가 포함되어 있습니다.
      export const x_snc_example_to_do = Table({
          name: 'x_snc_example_to_do',
          schema: {
              deadline: DateColumn({ label: 'deadline' }),
              state: StringColumn({
                  label: 'State',
                  choices: {
                      ready: { label: 'Ready' },
                      completed: { label: 'Completed' },
                      in_progress: { label: 'In Progress' },
                  },
              }),
              task: StringColumn({ label: 'Task', maxLength: 120 }),
          },
      })
      주:
      Record API를 사용하여 전용 API가 없는 애플리케이션 메타데이터를 정의할 수 있습니다.
    6. @servicenow/sdk/core에서 API에 필요한 가져오기를 추가합니다.
      예를 들어 날짜 열과 문자열 열이 있는 테이블을 정의하려면 Table API에서 사용할 해당 개체를 임포트합니다.
      import { Table, DateColumn, StringColumn } from '@servicenow/sdk/core'
    7. 옵션: 비즈니스 규칙과 같은 서버 측 스크립트를 사용하는 API의 경우 ServiceNow Fluent JavaScript 모듈에서 코드를 가져와서 객체의 스크립트 속성에서 호출합니다.
      이 예제에서는 script 속성에서 참조할 수 있는 showStateUpdate 함수를 가져옵니다.
      import { showStateUpdate } from '../server/script.js'
    8. 변경 내용을 저장합니다.

    를 사용하여 소스 코드에서 애플리케이션 메타데이터 정의 ServiceNow Fluent

    .now.ts 확장명을 가진 파일에서 API의 ServiceNow Fluent 개체를 사용하여 응용 프로그램의 메타데이터를 정의합니다. @servicenow/sdk/core에서 API에 필요한 가져오기도 포함해야 합니다.

    다음 예시에는 애플리케이션의 테이블, 클라이언트 스크립트 및 비즈니스 규칙의 정의가 포함되어 있습니다. 비즈니스 규칙은 script.js JavaScript 모듈의 함수를 사용합니다.
    import '@servicenow/sdk/global'
    import { BusinessRule } from '@servicenow/sdk/core'
    import { ClientScript } from '@servicenow/sdk/core'
    import { Table, DateColumn, StringColumn } from '@servicenow/sdk/core'
    import { showStateUpdate } from '../server/script.js'
    
    //creates todo table, with three columns (deadline, status and task)
    export const x_snc_example_to_do = Table({
        name: 'x_snc_example_to_do',
        schema: {
            deadline: DateColumn({ label: 'deadline' }),
            state: StringColumn({
                label: 'State',
                choices: {
                    ready: { label: 'Ready' },
                    completed: { label: 'Completed' },
                    in_progress: { label: 'In Progress' },
                },
            }),
            task: StringColumn({ label: 'Task', maxLength: 120 }),
        },
    })
    
    //creates a client script that pops up 'Table loaded successfully!!' message everytime todo record is loaded
    ClientScript({
        $id: Now.ID['cs0'],
        name: 'my_client_script',
        table: 'x_snc_example_to_do',
        active: true,
        applies_extended: false,
        global: true,
        ui_type: 'all',
        description: 'Custom client script generated by Now SDK',
        messages: '',
        isolate_script: false,
        type: 'onLoad',
        script: script`function onLoad() {
            g_form.addInfoMessage("Table loaded successfully!!")
        }`,
    })
    
    //creates a business rule that pops up state change message whenever a todo record is updated
    BusinessRule({
        $id: Now.ID['br0'],
        action: ['update'],
        table: 'x_snc_example_to_do',
        script: showStateUpdate,
        name: 'LogStateChange',
        order: 100,
        when: 'after',
        active: true,
    })

    애플리케이션을 빌드한 후 이 소스 코드는 인스턴스에 다음과 같은 애플리케이션 메타데이터 파일을 생성합니다.

    그림 1. 코드에서 ServiceNow Fluent 생성된 애플리케이션 메타데이터
    예제 코드에서 생성된 애플리케이션 파일입니다.

    다음에 수행할 작업

    소스 코드를 애플리케이션 메타데이터로 컴파일하고 인스턴스 전체에서 변경 내용을 사용할 수 있도록 애플리케이션을 빌드합니다. 자세한 내용은 에서 애플리케이션 빌드 ServiceNow IDE 문서를 참조하십시오.