HOW TO PRINT THE RESULT OF A BUSINESS RULE ON THE CONSOLE?

hibye
Giga Contributor

for example i want to print all the active records

i created a business rule by following conditions

when to run:

      BEFORE INSERT/UPDATE

      SCRIPT:

var x=new GlideRecord('incident');

x.addActiveQuery();

x.query();

while(x.next())

{

gs.print('active record number'+x.number);

}

but i am not getting any out put on the console

  i want to test all the GlideRecord methods with output how it is possible??

6 REPLIES 6

Kannan Nadar
Tera Guru

Hi Shabbir,



you have to use gs.log("Your Message"); inside business rule.


Mrudula6
Mega Guru

Hi Shabbir,



You can try below methods to print your results for testing purposes on SNOw screen,



1. gs.addInfoMessge("your message" +x.number); --> Will be displayed as info in blue color


2. gs.addErrorMessage("your error message" +x.number) ; --> Will be displayed as error in red color



You can find more glide system elements in this link GlideSystem - ServiceNow Wiki


hibye
Giga Contributor

i tried it but i am   not getting the output


this is my code::


var x=new GlideRecord('incident');


x.addActiveQuery();


x.query();


while(x.next())


{


gs.addInfoMessge("the active incident number is " +x.number);


}


Maybe a silly question but do you have active Incidents in your Incident table? Also, what conditions are triggering this rule? Is it definitely firing? Also, you've spelled addInfoMessage wrong.



try changing the loop to and if and say:



if (x.hasNext()){


gs.log('There is an active Incident');


}



hasNext() returns true or false depending on your conditions, if this doesn't return an response then you have no active incidents.