May 12, 2023

Scoped APIs are not Global enough

Scoped apps were first introduced in the Fuji release. This was a really exciting time for ServiceNow partners, developers, and the community. For partners, an app store within the ServiceNow ecosystem was a new business model. For developers and admins, there was finally a way to get away from update sets and there were lots of new features to play with. For just about everyone, there was a new way to encapsulate or “sandbox” business logic and data. This idea was and still is welcomed by me; I enjoy creating scoped apps and encourage my customers, and colleagues to embrace them.

For those that don’t remember the early days of scoped apps, we were all a bit shocked and surprised at how limited the APIs were. As time progressed, ServiceNow began exposing more and more “Scoped APIs” and today, I would say most if not all of the necessary APIs are exposed in the “Scoped” world. To get to that point, it took a great deal of feedback from the ServiceNow community to explain to the development team why some of these APIs are crucial to build amazing applications on the ServiceNow platform.

More recently, I see that we are faced with the opposite issue. Some scoped APIs do not function within the global scope. The frustrating piece is, it seems to be at random which APIs work and which don’t. If you regularly explore the developer site looking over the API documentation (as I do) you may have seen this disclaimer:

“**Please note: **The APIs below are intended for scoped applications and may behave differently in the global scope.”

Within the platform, specifically in the Global scope, I should be able to use APIs that are available to a scoped app or a similar equivalent API. I know that scoped apps are the future and that we should all be adopting them. With a few caveats I agree with this but that is not for this post to discuss. It seems as more Scoped API use cases have emerged, ServiceNow has built some amazing APIs for developers to use, however some of them were not ported into the global scope.

Consider the following example:

var att = new GlideSysAttachment().getContentStream(attachment);var xmlDoc = XMLDocument2(att);;

This code executes properly is a scoped app, however in the global scope, it does not. It produces the following error:

Evaluator: org.mozilla.javascript.EcmaError: Method "XMLDocument2" called on incompatible object.   Caused by error in script at line 2

This leads me to believe the correct method signatures were not setup in the global scope. Because the XMLDocument2 API, works in other contexts:

//Example from developer.servicenow.comvar xmlString = "<test>" +                "  <one>" +                "    <two att=\"xxx\">abcd1234</two>" +                "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +                "    <two>another</two>" +                "  </one>" +                "  <number>1234</number>" +                "</test>";var xmlDoc = new XMLDocument2();xmlDoc.parseXML(xmlString);;

This is just one example, I am sure other similar examples exist. My hope here is that while developing Scoped APIs, ServiceNow still considers that some use cases need to exist in the Global scope. Thus, Global APIs should have all of the APIs that exist in the Scoped world or at least a similar equivalent.

I share this feedback in hopes to better ServiceNow as a platform for all use cases.