- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 07:37 AM
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.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 07:44 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 07:53 AM
Oh i see. The script is meant to update u_gjeldene_leiepris in the u_leiekategori table to the same as u_maanedspris wich is in the u_leiepris table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 08:57 AM
Hi,
Understood. Yeah, you're close, you just need to actually query that table to find record on the u_leiekategori table. Then when you've found that related record, set the value and update it, as you've done.
So you're just missing the part around addQuery, for example, to find the related record (do you have it's number? or sys_id value? etc.) and then query and then if next, do the update.
All of what I've mentioned above is in the documentation I provided. It has examples of using GlideRecord with addQuery and querying and doing 'x'. Look at that for assistance.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 10:21 AM
Hello.
Thank you so much for the helpfull responses, im quite new to service now as i just started with it 6 months ago.
I have the sys id for the leiekategori table: 18f451e7873b34102ca6b80c8bbb3538
So i just do as you say and query that table into the script?