debug, gs.log doesn't work in business rule

jean-lucchatton
Kilo Guru

Hi,

I'm facing a weird issue in a business rule : the gs.log() doesn't write anything in the syslog.

We have defined an application menu "Assigned" to get the incident assigned to the groups that a person belongs to. In the menu, we set a filter condition "assignment group is javascript:GetMyGroups"

find_real_file.png

The function "getMyGroups" is OOB and defined in the business rule "groups, banners". As we wish to return only specific groups (i.e. the groups for assignment not the technical ones), I wish to change the code (I will make a copy).

So I've began with a gs.log, but it doesn't write anythink in the syslog

function getMyGroups() {

  gs.log("IN GET MY GROUPS OOB");

  return gs.getUser().getMyGroups();

}

Very strange....

Could you help me ?

Thanks

Jean-Luc

1 ACCEPTED SOLUTION

Thanks Jean-Luc. Didn't you say that this is a scoped app? If so, gs.log is off limits. Change it to gs.info and see if your script produces output. For best visibility to what's going on, turn on business rule debugging.



System Diagnostics> Debug Business Rule (details) and observe the output at the bottom of your form or list after   you save your changes.


View solution in original post

12 REPLIES 12

gs.log() is going to stop your script and throw an error since it's not an acceptable logging method in scoped apps.



http://wiki.servicenow.com/index.php?title=Scoped_Script_Logging


Chuck Tomasi
Tera Patron

If you use an explicit function name in a business rule, you need to call that. It would help if we saw the rest of the business rule record with the entire script, plus understand what you are trying to accomplish. In short.



function myFunction() {


        // Here's where I do something


}



Is just a declaration. You need to call it somewhere (outside of that declaration) like this:



myFunction();


function myFunction() {


        // Here's where I do something


}



Alternatively, you can use a self-invoking function call to short this up a bit (parenthesis and curly braces placement is extremely important!)



(function myFunction() {


        // Here's where I do something


})();


Hi Chuck,



Thanks for your answer. The issue is not about calling a function in a business rule - that works - , but that the gs.log in the business rule has zero effect.



Jean-Luc


Thanks Jean-Luc. Didn't you say that this is a scoped app? If so, gs.log is off limits. Change it to gs.info and see if your script produces output. For best visibility to what's going on, turn on business rule debugging.



System Diagnostics> Debug Business Rule (details) and observe the output at the bottom of your form or list after   you save your changes.


Hi Chuck,



The gs.info() is the solution thanks.



I've found two alternatives that allow the use of gs.log() : fix script and application menu script. From these scrpt, call the original script.



By the the way   :


1) The function JSUtil.logObject is very valuable ! Good work from the ServiceNow Team.


2) The Template that come when we create a Script include is not very easy to understand. A single function in a script include - with the same name - can most of the time do the job in a simplier way.



Jean-Luc