Exploring the ServiceNow SDK

  • Release version: Washingtondc
  • Updated February 1, 2024
  • 5 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Exploring the ServiceNow SDK

    The ServiceNow SDK enables developers to create and modify scoped applications locally using Visual Studio Code. This allows for offline development and leverages advanced coding features. Starting with the Washington DC release, developers can install these applications on non-production instances.

    Show full answer Show less

    Key Features

    • Local Development: Build applications offline in Visual Studio Code, utilizing ServiceNow Fluent for application metadata and custom JavaScript modules.
    • Command-Line Interface (CLI): Manage application changes with CLI commands, including authentication, creation, transformation, building, and installation.
    • Application Structure: Applications consist of source code files and metadata, organized similarly to Node.js applications, allowing for code reuse and modularity.
    • Configuration Options: The now.config.json file allows customization of the application structure and metadata handling.

    Key Outcomes

    By using the ServiceNow SDK, developers can:

    • Seamlessly develop and test applications locally before deploying them to an instance.
    • Maintain synchronization between local and instance application metadata.
    • Utilize structured project management through files that define dependencies and configurations.
    • Enhance application functionality with JavaScript APIs and third-party libraries.

    Learn about developing scoped applications in source code locally and installing changes on an instance with the ServiceNow SDK.

    ServiceNow SDK overview

    With the ServiceNow SDK, you can create and modify scoped applications locally in Visual Studio Code Desktop and install those applications on a non-production instance beginning with the Washington DC release. By developing applications locally, you can work offline and use Visual Studio Code development features.

    In Visual Studio Code, you can develop scoped applications in source code using ServiceNow Fluent to define application metadata [sys_metadata], write custom JavaScript modules, or add third-party libraries.

    The ServiceNow SDK includes a command-line interface (CLI) for managing changes between an instance and a local application. Using simple CLI commands, you can authenticate to an instance, create or convert an application, transform application metadata (XML) into ServiceNow Fluent code, build and install the application on the instance, and more.

    ServiceNow SDK workflow

    The following infographic shows the workflow for developers to get started developing applications with the ServiceNow SDK.

    Figure 1. Developing applications with the ServiceNow SDK
    Process for using the SDK in a local environment to develop applications and interface with an instance. For details, refer to the following description.
    1. A developer installs the ServiceNow SDK locally. For more information, see Install the ServiceNow SDK in an application.
    2. Using the CLI, the developer authenticates to a non-production instance to interface between their local environment and the instance with the now-sdk auth command. The developer must have the admin role on the instance.
    3. The developer creates a scoped application (now-sdk init) or converts an existing scoped application from the instance (now-sdk init --from) for use with the ServiceNow SDK.
    4. In Visual Studio Code, the developer can define application metadata in source code using ServiceNow Fluent, create custom JavaScript modules, or use third-party libraries.

      They can also download application and script dependencies from the instance to code against (now-sdk dependencies).

    5. The developer builds the application, which compiles the source code and transforms it into application metadata for the instance, and generates an installable package (now-sdk build).
    6. The developer installs the application on the instance (now-sdk install).
    7. Other users can continue to modify the application metadata on the instance, and developers can reuse the code from modules in other modules or scripts within the application.
    8. The developer downloads and transforms application metadata from the instance to get the latest updates to the application metadata locally (now-sdk transform), keeping it synchronized with the application on the instance.

    ServiceNow SDK benefits

    Benefit Feature Users
    Develop applications offline, outside of an instance in Visual Studio Code Developing applications with the ServiceNow SDK

    Visual Studio Code documentation

    Developers
    Write source code to define the metadata that makes up ServiceNow applications ServiceNow Fluent Developers
    Organize and reuse code within scoped applications with custom JavaScript modules and third-party JavaScript utilities JavaScript modules and third-party libraries Developers

    Application structure

    Custom scoped applications created with the ServiceNow SDK include source code files and metadata XML files. The package.json and now.config.json files define the application structure, which is similar to that of Node.js applications or Node Package Manager (npm) packages.

    By default, applications include the following directories and files. You can modify certain aspects of the application structure to suit your needs in the now.config.json file.

    .now
    Directory containing caching and metric information for the build and install processes.
    dist/app
    Directory containing the build artifacts for packaging.
    metadata

    Directory containing the application metadata (XML) of the application, such as table schemas and business rules, organized in the same directory structure as existing ServiceNow applications.

    Note:
    Application metadata shouldn't be edited from the XML files. Edit application metadata in the source code or on the ServiceNow AI Platform.
    node_modules
    Directory containing the third-party Node.js modules on which your application depends.
    src
    Directory containing the source code of your application. This directory includes the following subdirectories:
    • fluent: Directory containing ServiceNow Fluent code in .now.ts files. The generated subdirectory contains the application files converted to ServiceNow Fluent.
    • server: Directory containing JavaScript module code in .js or .ts files.
    target
    Directory containing an installable package (.zip file) to upload to an instance.
    .eslintrc.json
    File containing the ESLint configuration. ESLint helps identify and fix issues in the application code.
    .gitignore
    File containing a list of directories or files for Git to ignore. These files aren't tracked in source control.
    now.config.json
    File containing the ServiceNow application configuration. The now.config.json file must be in the base directory for an application.
    You can configure the directory structure for an application by adding the following parameters. For example:
    {
      "scope": "x_snc_example_app",
      "scopeId": "2f8400eb07426110f736e28f69d3017a",
      "name": "ExampleApp"
      "metadataDir": "metadata",
      "fluentDir": "src/fluent",
      "serverModulesDir": "src/server",
      "appOutputDir": "dist/app",
      "packOutputDir": "target",
      "modulePaths": {
          "src/server/*.ts": "dist/server/*.js",
        },
      "ignoreTransformTableList": ["ua_table_licensing_config", "sys_embedded_help_role"]
    }
    Table 1. Supported now.config.json parameters
    Parameter Description
    metadataDir Directory containing the application's metadata as XML files.

    Default: metadata

    fluentDir Directory containing ServiceNow Fluent files (.now.ts) that define application metadata in source code.

    Default: src/fluent

    serverModulesDir Directory containing the JavaScript or TypeScript files to be built into JavaScript modules for use in server-side scripts.

    Default: src/server

    appOutputDir Directory to output the build artifacts to for packaging when building the application. The build command refers to this directory package the artifacts.

    Default: dist/app

    staticContentDir Directory to output the static asset files used for front-end development.

    Default: dist/static

    packOutputDir Directory to output the installable package (.zip file) when building the application. The install command refers to this directory to install the package.

    Default: target

    modulePaths A map of the module source files to their equivalent output files for if you use a custom transpilation step before building the application. For more information, see Using TypeScript in JavaScript modules with the ServiceNow SDK.
    Warning:
    You can't use this parameter and the tsconfigPath parameter. Configuring both results in an error.
    tsconfigPath A path to a tsconfig.json file with custom options for transpiling TypeScript into JavaScript during the build process. Specifying a tsconfigPath generates diagnostic results from TypeScript using the tsconfig.json file.
    Warning:
    You can't use this parameter and the modulePaths parameter. Configuring both results in an error.

    Default: .

    ignoreTransformTableList Tables to ignore when transforming application metadata into source code.
    package-lock.json
    Auto-updated file containing complete information about dependencies and their versions. This file is only available with the ServiceNow SDK.
    package.json

    File containing information about your application and custom or third-party module dependencies. The package.json file must be in the base directory for an application. On an instance, the package.json path is specified in the Package JSON field of the custom application record [sys_app] in the format <scope>/<package-name>/<version>/package.json.

    tsconfig.json

    File containing the TypeScript configuration, type definitions, and options for compiling TypeScript files into JavaScript modules.

    Related applications and features

    JavaScript APIs
    Use JavaScript APIs in scripts that you write to change the functionality of applications or when you create applications.