JS calls from Global scope running ES5 and a custom Scope running ES12. Now-sdk required command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 02:12 PM
How does ServiceNow handle cross-scope calls between a Global scope running ES5 and a custom Scope App running ES12? Also, how is the now-sdk “require” function implemented in Washington?
Here is my testing example:
• I’ve created a Scope App: sdk_demo.
• “JavaScript Mode”: ECMAScript 2021 (ES12)
• In the scope app, I’ve created a script called: x_<#####>_demo.SdkManager
• Code example:
var SdkManager = Class.create();
SdkManager.prototype = {
initialize: function() {},
run: function(name) {
const text = `Hello ${name}`;
gs.addErrorMessage(text);
},
type: 'SdkManager'
};
I’ve created a BR on the wm_task table in the Global Scope on Insert and Update:
(function executeRule(current, previous /*null when async*/ ) {
try {
var utils = new x_<#####>_demo.SdkManager();
utils.run('test.....');
} catch (ex) {
var msg = ex.message;
gs.debug(msg);
gs.addErrorMessage(ex.message);
}
})(current, previous);
This code works.
My questions come from planning around with “now-sdk”
if the script includes was altered to use the initial myFunction.js that now-sdk creates (by default):
var SdkManager = Class.create();
SdkManager.prototype = {
initialize: function() {},
run: function() {
const {
showStatusUpdate
} = require('./src/myfunction.js');
showStatusUpdate(current.getValue('status'), previous.getValue('status'));
},
type: 'SdkManager'
};
This works if I create a BR on a table in the same custom Scope App:
(function executeRule(current, previous /*null when async*/) {
let mgr = new x_<#####>_demo.SdkManager();
mgr.run();
})(current, previous);
But if I go back to the wm_task table and run, it generates the error:
“require” is not defined
From this experiment came the two questions:
• How does ServiceNow handle cross-scope calls between a Global scope running ES5 and a custom Scope App running ES12?
• How is the now-sdk “require” function implemented in Washington?
Any insight would be helpful.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 06:27 PM
I also ran another test by creating an additional Scoped App running ES12.
In this scoped App, I created:
- Test table
- Script Include
- Business Rule (on Update)
The script include would call the:
let mgr = new x_<#####>_demo.SdkManager();
mgr.run();
We receive the same error when the Business rule calls the Script Include.
“require” is not defined
So the require method seems to be restricted to the Scope App where the now-sdk is deployed to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 06:42 PM
Even if you create two separate Scope Apps via the now-sdk, you can't call the other Scope App functions created with the now-sdk. You'll always receive the error: “require” is not defined