logo

NJP

Forget about adding log statements to Server Side script, use logpoints! [Orlando]

Import · Feb 16, 2020 · article

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

Hi there,

Ok don't forget completely about adding log statements to Server Side script image Though I wanted to highlight a really nice small addition made in the Orlando release on the Script Editor. A small addition called "logpoint". When enabled you could simply add a "logpoint" - similar like a breakpoint - on which you could add a temporary log statement, without updating/changing the actual script!

So it should be more flexible, no updates on scripting needed anymore, no accidental log statements transferred to production and you could use this for debugging purposes on any instance.

Working with the Script Editor

Not familiar (enough) with working with the Script Editor? A few weeks back, I wrote an extensive article about "Utilizing the Script Editor". This article also contains the additions made to the Script Editor with the New York release.

Orlando

With the Orlando release, the Script Editor has been enhanced again. Two catching enhancements I would like to highlight:- Find References;

- Logpoint.

Find References is available when performing a right-mouse click on recognized Script Includes in the Script Editor and selecting "Find References" from the context menu. Basically, this will generate a list of files referencing the Script Include. Read more about this on the Docs: JavaScript syntax editor [https://docs.servicenow.com/bundle/orlando-application-development/page/script/general-scripting/con...]

image

Logpoint is available when performing a right-mouse click on a line number on the Script Editor within the Platform UI and selecting "Add logpoint" from the context menu. Basically, this will set breakpoints or conditional logpoints to log messages to the console at specific lines and remove logpoints when you are done debugging them.

image

Activating logpoints

Out-of-the-box the logpoints functionality is not activated. You can easily activate this through setting System Property "glide.debug.log_point" to "true".

Using logpoints

To get your first touch on using logpoints, let's just add a new Business Rule on the Incident table, which triggers on Update, maybe add a condition like Short Description changes. Within the Script field of the Business Rule, on a random line number simply right-mouse click for the context menu to appear. Here you could add something like "gs.info('>>>DEBUG: Orlando logpoints test')".

image

You can verify the logpoint was set by hovering over the greenish marking on the line number. Adding multiple logpoints to the same script is possible.

image

After setting the logpoints, activate the Debug Log. Do this by:1) Navigating to "System Diagnostics > Session Debug > Debug Log"- OR -

2) Opening the Script Debugger from the Script Editor toolbar and activating "Log" under "Settings".

When triggering this Business Rule, the logpoint should have generated the gs.info statement. When opening the System Logs you should be able to find your log statement.

image

This could also be done when using the Script Debugger.

image

Wow! Log statements generated without actually editing scripting, really nice.

Note: Add the logpoint on a line in the Script Editor which contains actual code being executed. If you would add the logpoint on a blanc line or a commented line, the logpoint will not be executed.

Platform UI versus Service Portal Designer, Virtual Agent Designer, etcetera

There is a "small" note I have to make… this all works really nice when using the Script Editor on the Platform UI. The Script Editor available on Script type fields. On Script fields on the Service Portal Designer, Virtual Agent Designer, etcetera… unfortunately, the behavior of the Script Editor is not exactly the same and actually very limited. The new enhancements described in this article, do not apply to the Service Portal Designer, Virtual Agent Designer, etcetera.

---

And that's it actually. If any questions or remarks, let me know!

Kind regards,

Mark Roethof

ServiceNow Technical Consultant @ Quint Technology

1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

image

View original source

https://www.servicenow.com/community/developer-articles/forget-about-adding-log-statements-to-server-side-script-use/ta-p/2309992