scenarios where we use background scripts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 08:25 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 09:01 AM
Administrators can run any valid JavaScript that uses the Glide API. The system displays results, information, and error messages at the top of the screen.
Example: http://wiki.servicenow.com/index.php?title=Useful_User_Scripts#gsc.tab=0
You can navigate to system definition -> scripts -> Background to open the run your code.
Note: Running free-form JavaScript can cause system disruption or data loss. ServiceNow does not recommend running free-from scripts from a production instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 01:42 PM
Hi,
This is my simple answer - I would use Background script
1. Correctness/ debug -> To test my javascript errors script
ex. If i have long script which runs on any events and I don't want to go through that entire process every single time. I would run snippets in background script to debug my script and output.
2. One time job/ Stand alone jobs -> One time manual job run
ex. If I have to create, update, or delete records, import data
from any table or perform any upgrade or something which is only one time thing I would run it from script background.
You need to be extra careful while running business rules.
for more -
Background Scripts — ServiceNow Elite
Thanks.
PS: Hit like, Helpful, Correct and Endorse, if it answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 08:35 PM
I would like to slightly differ from others on this. I would discourage the use of background script on Production environment and would encourage you to always use on-demand schedule job for running even one time job.
- This would help in governance and you will be able to verify what scripts are/were being run.
- The scripts would run on scheduler worker rather than on your node.
- Cancelling/killing job is easier.
Other than running some light weight scripts on non-prod environment, I would never use background scripts.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 08:46 PM
I agree with Kalai,
Dont use background script on Production.
If you want to perform some mass update using background script, run it on DEV first. But use it for small operations, such as updating a value of a record or query some database value.
Background scripts are server side scripts, using which you can run any independent script. Using it for bulk update or any huge job could cause service disruption and performance degradation. So careful while running any such script on Production.
Please mark this response as correct or helpful if it assisted you with your question.