Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to call a global script include from now-sdk?

anthonydian
Tera Contributor

 Hi now-sdk community,

 

I struggle to complete the following task: calling a global script include from my now-sdk scopped application.

 

When the following snippet runs well in a bg script (executed from my application scope): 

var test = new global.inboundAPILog().insertEventLog('x_frt_orangetmf697.inbound.api.event', null, "","");

The exact same script deployed through now-sdk will produce this error: "undefined is not a function".

Surprisingly, if I open the deployed sys_module in my browser, the global script include is well found, and I can navigate to it with control+click : 

anthonydian_0-1753796827515.png

I haven't found any resources on this specific topic, does this speak to you?

 

Thanks a lot for your feedback,

Regards,

Anthony



11 REPLIES 11

anthonydian
Tera Contributor

Hi,

 

The target script include is accessible from all scopes (see attachment).

 

When i'm running the bg script, i'm running it from "x_frt_orange_sdk" scope, which is my now-sdk app scope (see second attachment).

I'll give a try to remove the global. prefix in my script source code and I'll keep you in touch.

 

Regards,
Anthony

Harish Kumar Sr
ServiceNow Employee
ServiceNow Employee

Hey @anthonydian

I believe you are trying to call the global script include from a module. To achieve that you could do the following,

import { global } from '@servicenow/glide'

export function someAPI() {
   var test = new global.inboundAPILog().insertEventLog('x_frt_orangetmf697.inbound.api.event', null, "","");
   //do something with the result
}

 
The module requires the import statement for it to resolve the scope and script include on the instance. Let me know if this fixes your issue.

ChristianGraab
Tera Contributor

@Harish


How would this work if the script include is from a different scope than the global scope? 
I am trying to use a script include exposed by a different application, but I cannot figure out how to use the import. 

Also, could I expose a module from the other application, instead of a script include? 

//Christian

Hi @ChristianGraab,

 

first of all, such a script include must be accessible 

GlideFather_0-1762514902690.png

 

and then if it is cross-scope then you just ened to add a scope prefix global.sandstormUtil as seen in the API name above.

 

so as example you would call it from other app using:

new global.sandstormUtil().yourFunctionName();
_____
This reply is 100 % GlideFather and 0 % AI

Hi @GlideFather 

This that part works. 

But let's say I want to use the a script include from another scope, I would do this in a regular Script Include or Background Script. 

var util = new x_mycompany_appScope.loggingUtil().logStuff('message')


But I cannot figure out how to do this from the now-sdk app.
I have tried looking at the examples on github (https://github.com/ServiceNow/sdk-examples), but that didn't help me in understanding it better.

I have tried doing: 

import { x_mycompany_appScope } from "@servicenow/glide";

But this doesn't seem to be the correct way of doing it, since it just becomes undefined.