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
Post a Comment