- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 02:13 AM
Hello, everyone!
As far as I realise, this is a very basic question, yet googling for 2nd day straight I cannot find a definite answer to this simple question:
How do you write to any kind of log from a script action? How do you read that log? Examples, please.
I can "log" a business rule using client message (not perfect but works for development purposes), but it won't work from script action. The script action in question keeps generating errors and I cannot find what kind of error it is or how to fix it.
I tried using Javascript debug log from gear icon but it doesn't seem to print anything from script action, or I'm doing it wrong. I tried looking into event logs but can't find any useful information, or I'm trying to log it wrong.
Extra information:
I'm working on "coding on ServiceNow" training course, module 8, excercises 26-27, I created a script action that should update number of marketing event attendees whenever a new attendee is registered or deleted. Adding one works fine, deleting one generates an error. I cannot find any info on the error other than the fact an error occurred. I'm trying to log relevant into to understand the reason behind error. I've re-checked all related code several times already and found no errors.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 02:26 AM
You can put a log statement in script action like below as it is server sided.
gs.log("This is a log statement");
and you can check it under System Logs module
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 02:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 03:24 AM
Thanks a lot, found my logs. I received a message stating "log" is not allowed in my context (in my app?), and advice to use info instead. I changed log into info and it prints my info correctly. Your message was very helpful in locating the log as well. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2017 02:28 AM
Hi Yuri,
When you say log a message, is it a message to user on the UI or debug log in the System Logs?
For adding debug logs from script action, you can use gs.log("My Log", "Soure");
You can add user messages on UI from a script action as it runs at the background. Information or Error Messages to users can be done from client scripts or business rules.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response