How to set Log level to Error and trigger notification

Katie A
Mega Guru

Hello, I have a business rule. I want to write an error to the system log.

I typically just use :   gs.log()

How can I set the "level" to "error"?

Also, how can I trigger a notification if this specific error is encountered?

I read this wiki page but I do not know what system property to use.

GSLog - ServiceNow Wiki

var gl = new GSLog("com.snc.sla.tasksla.log", "TaskSLA");       // ???????

gl.logErr("This is an error message");

1 ACCEPTED SOLUTION

I just placed


gs.error('Test')

and


gs.info('Test')

into a non-scoped or Global scoped app Business Rule and here are the results:


gsinfoerror.PNG


View solution in original post

8 REPLIES 8

Chuck Tomasi
Tera Patron

Hi kda617,



Have you tried gs.error()? This, and gs.debug/info/warn were introduced in Fuji as part of the scoped app API. In fact, gs.log() is not allowed in scoped apps.


The problem with gs.debug/info/warn is that you cannot set the source. So to make clear where the log is coming from you have to add it to the content of the log, which is rather ugly.


Abhinay Erra
Giga Sage

The first parameter you see in the GSLog class is a system property (com.snc.sla.tasksla.log) which defines log level. Define you own system property(sys_properties) and give the value "err" if you want that as an error and use that as your first parameter.


jeremyeperdue
Giga Expert

What version of ServiceNow are you on?


In Geneva there is auto complete for some code. So you can open a business rule and set it to advanced and type gs. and see a list of available options.


I think best practice has moved away from gs.log and towards gs.info, gs.error, gs.debug etc...


gs.<verbosity_level>(message [, parameters])




Scoped Script Logging - ServiceNow Wiki