Background scripts are always run in global scope

Krishna119
Kilo Contributor

Experience of running background scripts is not the same in VS Code vs Instance (Scripts - Background)

While VS Code status bar shows the current scope, Background Script always runs in rhino.global scope, making scoped scripts untestable. For example, I cannot use deleteMultiple on a scoped table, obviously.

Is scope even supported?

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Krishna,

you can use scheduled job to execute your scripts in scoped app instead of background scripts

Background scripts are not recommended; they can just be used to get some information etc but not to be used to update multiple records or delete multiple records

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

deleteAll was just an example. Issue is about option to set scope which is available on instance.

Shasank
ServiceNow Employee
ServiceNow Employee

The Background script runner in the extension works in tandem with the active application.

 

So you can run the Background scripts either in

  • Global scope
  • Current application scope

Krishna119
Kilo Contributor

Okay, I guess the problem statement is unclear.

When I use either

  • Run Background Script - Current (OR)
  • Run Background Script - Global (OR)

menus, the script is always running in Global scope.

My current scope was set to an Application when I opened a file from it in VS Code and I can see it on the status bar.