white and black checkered brick toys stacked on top of each other forming ladder

Some time ago (probably around February/March 2024) ServiceNow added some documentation pages about their new tool – SDK. If you know a bit about node.js development, you could also easily find an npm package. I haven’t seen any big announcements yet, but I decided to check it out. And it was worth it, see my findings below. But first, let’s make a quick history reminder.

What are Javascript modules?

The modules in javascript are code packages that can be imported into other node.js applications or different modules. They were introduced with ES6 but did not make it to the ES12 scoped app update in Tokyo release. I guess it was too much, and I can really understand that now. The way the platform is evolving makes me believe they do have a long-term plan to introduce new features.

Modules come in different flavours – we have CommonJS, AMD, UMD and ECMAScript or ES in short. ServiceNow has adapted the latter, being also the most popular and easy to understand one. And, as a matter of fact, the official one for packaging javascript code for reuse. Here are some very technical details about it.

Of course, there are some limitations for modules in SN, but there always have been and it doesn’t bother me at all. It simply proves that the platform owners know what they are doing and don’t push everything.

Great thing about modules is that although they have to be loaded from server side, they can be also used in the browser. I haven’t checked that yet, but just imagine the new ways of building UI Pages or widgets with reusable modules!

Does it work at all?

Yes it does! I have a very basic example of developing, building, deploying and using a module:

  1. Install nvm on you development machine (you will use it to install node.js)
  2. Install the latest build of node.js (works on 22.1.0)
  3. Install the @servicenow/sdk module (yes, it’s the same technology)
  4. Follow the basic procedure – authenticate to the instance, create/convert an app
  5. Write your code
  6. Build it
  7. Deploy it
  8. Use it

I ran my module from background script – since it works on server side. Simple code like:

import { gs } from "@servicenow/glide"

export const sum = (a, b) => {
    gs.addInfoMessage(`${a} + ${b} = ${a + b}`);
}

Executed like:

const test = require("path_to_my_module.js");
test.sum(1, 2);

Resulted in expected message:

Background message, type:info, message: 1 + 2 = 3

Now, how did I get path_to_my_module.js? From the sys_module table.

That’s it, it’s pretty simple. There is a great documentation page where you can get even more details.

That sounds like exactly the same thing as a script include…

True. But:

  • modules are a modern way of sharing your code, adapted by plenty of regular javascript developers
  • modules allow using typescript on the ServiceNow platform (there is even a documentation page!)
  • modules allow you to easily define dependencies
  • modules allow you to introduce 3rd party libraries to ServiceNow server-side scripting
  • modules are part of a javascript standard

That’s really great, but what about…

  • Code complexity? Yes, it grows. Developers need to learn more, but with all the resources available, is it really that hard?
  • Security? The code is executed on the server side. Also remember about the limitations.
  • Module debugging? As far as I know, not possible.
  • Maintenance? The module has to be maintained outside of the platform.

Conclusion

Overall, modules in ServiceNow are a great step forward. They may be currently too immature for most use cases, but they also give insights into the future of a modular platform. Due to the fact how much they resemble script includes with the added complexity, some developers may consider them a step back. I would rather call it going back to baseline with platform capabilities. Sounds familiar? You may have heard about it in your project.

Is there something that is possible with modules and wasn’t possible before? I don’t know and don’t think so. But definitely, working with modules is much easier. Especially when you are developing custom workspace components and want to everything, including server side logic as a single package that can be deployed to your instance. Or when you want to share your module.

I’ll keep exploring the subject and try to stay on top of things. Maybe I’ll even create my own module? The real benefit is that you can work on it locally, in your favourite code editor with syntax highligthing, testing tools. It is clearly a pro-code feature that should make the development on the ServiceNow platform fun again.

Leave a Reply

Your email address will not be published. Required fields are marked *