Issue with background script output page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi all,
Actually I am wondering why I am getting like this on output page(See screenshot). Lot of Unnecessary things, I just want to print the sys_ids of created incidents. In the background those incidents were created.
Is something enabled in my instance? earlier I don't used get this.
What should I do? Please assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @KS86 ,
You're logging grInc.sys_id, which returns a GlideElement object.
Instead, use any one of the following:
- grInc.getValue("sys_id")
- grInc.getUniqueValue()
- grInc.sys_id.toString()
Avoid accessing field values directly (for example, grInc.sys_id) as these returns GlideElement object and create issues if try to use array to store and fetch values, all elements references the same object.
Thanks
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ahoy @KS86,
try selecting "Stacked", there are some alternative views
✂-----Cutting-out-the---✦AI-noise✦---All-replies-written-and-vouched-for-by-GlideFather---
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @KS86
Because background scripts run in the current session, any system log or broadcast broadcasted by synchronous server-side processes will print directly to your screen.
Probable fix1 :
Before you call the .insert() or .update() method on your GlideRecord, append the following two control methods to your record object:
- gr.setWorkflow(false); – This completely stops Business Rules, Workflows, and Flows from triggering, which eliminates almost all background log pollution.
- gr.autoSysFields(false); – This prevents the system from automatically writing system fields (like updating sys_updated_on or creating standard engine tracking logs).
var i = 0
while (i < 5) {
var grInc = new GlideRecord('incident');
grInc.initialize();
grinc.caller_id = gs.getUserID();
grinc.short_description = "Created by background script";
gr.setWorkflow(false); // Stops business rules, workflows, and engines from triggering
gr.autoSysFields(false); // Prevents automatic system logging overhead
grInc.insert();
i++;
gs.info(grInc.sys_id)
Fix 2: This is I always do.
Run your background script with a clear prefix inside your print statement (like gs.print('MYLOG_ ' + data);).
You can then use your browser search (Ctrl + F) to step through only the lines prefixed with MYLOG_.
var i = 0
while (i < 5) {
var grInc = new GlideRecord('incident');
grInc.initialize();
grinc.caller_id = gs.getUserID();
grinc.short_description = "Created by background script";
gr.setWorkflow(false);
gr.autoSysFields(false);
grInc.insert();
i++;
gs.print('MyLog::'+grInc.sys_id);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @KS86,
You have syntax issue for gs.info line, add a semi colon and run it. Ignore other logs as it would be due to background jobs running.
Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.
Kind Regards,
Ehab Pilloor