Unlocking the Potential of ServiceNow's CLI

Reece PoulsenReece Poulsen
4 min read

If you've ever installed and setup the ServiceNow CLI you know that getting started is never easy. Between managing node versions, memorizing the commands, or managing the now-ui.json there is plenty of room for headache! Sure after a couple of tries, you can become familiar with common errors and get things started faster than normal, but the learning curve is a little discouraging!

That's why I decided to create the uib-component-cli npm package. The uib-component-cli is a wrapper around ServiceNow's CLI to add helpful functionality and improve user experience.

This post will highlight some of the improvements that were made.


Wrapper Approach

The uib-component-cli is a wrapper around ServiceNow's CLI, meaning that it still uses the Now CLI's commands but they are abstracted from the user. For example, the snc ui-component project --profile profile_name --scope scope_name --name project_name Now CLI command is used by the uibc setup command but the command is wrapped with some additional steps:

  • Check requirements

  • Prompt the user for project profile, scope, and name

  • Run the Now CLI command snc ui-component project --profile profile_name --scope scope_name --name project_name

  • Ask the user if they would like to remove the default component

    • Remove the default component if they said yes
  • Switch to the newly created component project folder and run npm install to install dependencies


Better Setup Experience

ServiceNow's CLI requires that you run it on Nodejs v12.16.1 or v14.21.3. If you don't meet that requirement you may see a 'Missing “Keytar” Module' error while running any of the commands. This error is not very helpful and can be frustrating to encounter because it doesn't provide you with any direction on how to fix it. After some searching, you might find that the cause of the problem is that you are running the wrong Nodejs version.

If you've never used Nodejs from the command line before, simply downloading and switching node versions can be a daunting task. If you try to use the yala-component-cli while running an incompatible version of Nodejs, it will print this error message that provides some helpful instructions:

- Checking requirements -
✖ Running incompatible version of node
In order to use the Now CLI you must be running node v12.16.1 or v14.21.3
Check the node versions you have installed by running 'nvm list'
If v12.16.1 or v14.21.3 is installed then switch node versions by running 'nvm use <version_num_here>'
If you don't have node v12.16.1 or v14.21.3 installed, then download one of them here:
https://nodejs.org/ru/blog/release/v12.16.1
https://nodejs.org/en/blog/release/v14.21.3
Once downloaded, run 'nvm install <version_num_here>' to finish the installation

Improved User Interaction

The uib-component-cli takes a prompt-based approach to interact with users rather than chaining command inputs, this helps reduce the learning curve.

Here's an example of a user interacting with the uibc setup command:


Added Functionality

uibc setup
The uibc setup command builds a new component project and installs the dependencies all in one command. This command also allows the user to remove the default component that is automatically created when a project is made
uibc create-component
The uibc create-component command adds a new component to your current project and the appropriate references for that component to the project index.js, now-ui.json, and example/element.js files. The newly created component folder contains helpful template files
uibc delete-component
The uibc delete-component command allows you to quickly remove a component and its references from a project
uibc add-property
The uibc add-property command adds a new property object to the now-ui.json file for a given component
uibc add-action
The uibc add-action command does a similar thing as the add-property command but instead, it adds an action. These two commands make working with the now-ui.json file much easier
uibc develop
The uibc develop command starts a live development server for your current project
uibc deploy
The uibc deploy command deploys the current project to a ServiceNow instance. This command also allows the user to save a zipped copy of the project folder locally and it attaches the zip to the application record on the instance. This approach ensures that an un-minified version of the code is stored both locally and on the instance
uibc create-xml
The uibc create-xml creates an update set xml file for the component project

Installation

If you are interested in trying out the uib-component-cli for your ServiceNow custom component development you can install the npm package by running:

npm install -g uib-component-cli
0
Subscribe to my newsletter

Read articles from Reece Poulsen directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Reece Poulsen
Reece Poulsen

Back in my freshman year of college, I was introduced to the world of programming, and it immediately caught my attention. The idea of creating something new with just a little learning and a couple of lines of code fascinated me—it was like discovering a whole new universe of possibilities! Ever since that moment, I've been on a continuous journey to expand my programming knowledge and skills. Now I'm a relatively new software developer on the ServiceNow platform, and I'm eager to explore its potential. Through this blog, I hope to share some of the things I'm learning along the way. Let's dive into the world of ServiceNow together and uncover the tricks and insights that can make a difference for us as developers!