How do i log my script?

asd22
Tera Contributor

How do i log my code so i can see in system logs where my script goes wrong?

 

(function executeRule(current, previous /*null when async*/ ) {

var grL = new GlideRecord('u_leiekategori');
var a = current.u_maanedspris;
grL.u_gjeldene_leiepris = a;
grL.update();


})(current, previous);

 

i wanna log this so i can view where the error happens.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Out of box, if there's an error here it'll automatically be captured in the system log.

However, based on what you're doing with GlideRecord, this may not throw an error and instead it'll create a record (because you didn't format this correctly to successfully query the table and are trying to "update" nothing...so a new record would be created).

You can insert your own logging though by using example:

(function executeRule(current, previous /*null when async*/ ) {

gs.info("***DEBUG - Hi I'm at the start of this script");
var grL = new GlideRecord('u_leiekategori');
var a = current.u_maanedspris;
gs.info("***DEBUG - This is the value set for JavaScript variable 'a': " + a);
grL.u_gjeldene_leiepris = a;
grL.update();
gs.info("***DEBUG - Bye!");


})(current, previous);

So the above shows 3 places I'm logging things.

Otherwise, you may want to review using a try catch: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

12 REPLIES 12

Do you want to update all the rows of that table?

 

-Anurag

No just the one u_gjeldene_leiepris to be updated with the same value as u_maanedspris

Murthy Ch
Giga Sage

@asd

You can use this syntax:

gs.info('Your code here');

You can see your logs under System Log> All

syslog.list

 

Thanks

Murthy

Thanks,
Murthy

Allen Andreas
Administrator
Administrator

Hi,

Out of box, if there's an error here it'll automatically be captured in the system log.

However, based on what you're doing with GlideRecord, this may not throw an error and instead it'll create a record (because you didn't format this correctly to successfully query the table and are trying to "update" nothing...so a new record would be created).

You can insert your own logging though by using example:

(function executeRule(current, previous /*null when async*/ ) {

gs.info("***DEBUG - Hi I'm at the start of this script");
var grL = new GlideRecord('u_leiekategori');
var a = current.u_maanedspris;
gs.info("***DEBUG - This is the value set for JavaScript variable 'a': " + a);
grL.u_gjeldene_leiepris = a;
grL.update();
gs.info("***DEBUG - Bye!");


})(current, previous);

So the above shows 3 places I'm logging things.

Otherwise, you may want to review using a try catch: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

Please review GlideRecord documentation for assistance with that piece: https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!