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



6 REPLIES 6

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.