Skip to main content

ServiceNow Background Script

What is Background Script in ServiceNow ?

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 & It can update the huge number of records at once. 

Scripts - Background was this magical place in the platform where you could run any server-side script. You can update ‘n’ number of records at once using background script & It is kind of testing ground for any server-side method you wanted to learn about or new script you would like to test because you don’t have to configure When to run logic around it like a Business Rule. Running a script in Scripts - Background was as easy as putting a script in the field and clicking the Run script button. 

NOTE: Scripts - Background should be used very carefully and only in non-production environments. Free-form JavaScript can negatively impact data and system performance.

Try using Setworkflow(false); & autoSysFields(false) whenever you are writing any background Scripts.

The place where you have to write background script in ServiceNow.

Examples of Background Script :

1.> Resolve the incident tickets which are In progress & opened before a week

var gr = new GlideRecord('incident');

gr.addEncodedQuery('state=2^opened_at<javascript:gs.beginningOfThisWeek()');

gr.query();

while(gr.next()) {

gr.state=6; //backend value of resolve state

gr.close_note='Solved Permanently'; //mandatory field while resolving incident

gr.close_code='succesfully completed';

gr.update(); }

gs.print('successful');

2.> Update the assignment group as “Application Development” of problem ticket whose state is assess 

3.> Close the problem tickets which are resolved 

4.> Insert user, problem, incident record

For your reference : Watch full video on YouTube Background Script video Link







Comments

Popular posts from this blog

Access Control List (ACL) in ServiceNow

First, Let's understand what is Access Control List (ACL) in ServiceNow? Access Control Lists are the process by which ServiceNow provides granular security for its data and can be applied to individual records, as well as fields within those records. Rules for access control lists (ACLs) restrict access to data by requiring users to pass a set of requirements before they can interact with it.  All access control list rules specify:  1.> The object and operation being secured  2.>The permissions required to access the object There are some important ACL record operation types  - create : Enables users to insert new records (rows) into a table. read : Enables users to display records from a table. write : Enables users to update records in a table. delete : Enables users to remove records from a table or drop a table. edit_task_relations : Enables users to extend the Task [task] table. edit_ci_relations : Enables users to extend the Configura...

Difference b/w After & Async Business Rule in ServiceNow

Let's try to understand difference b/w  After & Async Business Rule & some examples on Real time scenario of After Business Rule & Async Business Rule : 1.> After BR executes synchronously (It will wait for a result, once result is ready & get displayed then user will get control to do anything, user has to wait) but Async BR executes asynchronously (user will get control immediately, it will not halt the user and result will get displayed when its ready or get response from system, it will be executing in the background as per system scheduler). 2.>After BR is used to update information on related objects that need to be displayed immediately such as GlideRecord queries etc. whereas Async BR is used to update the information on related objects that do not need to be displayed immediately such as calculating metrics & SLA etc. 3.>We can use current & previous objects but We can’t use previous object in Async rule & current ob...

ServiceNow Reference Qualifier with real time scenario

Let's understand about ServiceNow Reference Qualifier which is quite important topic and  an be used to filter the data on reference field.  What is Reference Qualifier ? Use reference qualifiers to create filters that restrict the data that is returned for a reference field. What are types of Reference Qualifier ? 1.> Simple 2.> Dynamic 3.> Advanced 1.> What is Simple Reference qualifier ? Simple reference qualifiers use AND/OR statements (conditions) to create simple filters.  Ex - Use simple reference qualifiers when filtering on conditions such as whether a company is active, a user has a specific role, and/or a caller is in a specific time zone. 2.> What is Dynamic Reference Qualifier ? Dynamic reference qualifiers enable you to use a dynamic filter option to run a query against a reference field to filter the returned data set.  Ex- you can add dynamic filter created. In dynamic filter, you can call script include as per your requirement. Let's i...