- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 09:09 AM
I've got a two part question. The first is part is generic and relevant to anyone who searches this for historic purposes, second is specific to our environment and relates to debugging records getting created without my knowing where they're getting created from.
First: I'm looking to print a stack trace when I don't have an error. I've reviewed some of the knowledge articles from these forums and I've found this article which doesn't seem to work for me, with this snippet of code doing nothing:
try {
var gr = new GlideRecord('incident');
madeUpVariable.madeUpFunction();
} catch (e) {
gs.print('LineNumber :' + e.lineNumber);
gs.print('SourceName :' + e.sourceName);
gs.print('Name: ' + e.name);
gs.print('Message : ' + e.message);
}
How to Print Stack Trace via Script
Second: The reason why I'm trying to do this is because I've got an issue in our environment where we're using the Asset Management module. We're customizing the purchase order creation workflows and the ProcurementUtils script include. We've copied that utility and added our own business logic to the copy. We have a problem, however, where somewhere in our process there are purchase orders are getting created without requests at all. They're completely empty purchase orders, no data in them whatsoever beyond updated and created datetimes. Another symptom of this is that for every POLine in the original legitimate PO, it creates the same number of blank POs.
I can't find out where they're coming from. I've added logging to my code to determine when I'm calling the ProcurementUtilsRBC.createPO(request, vendor, destination), and I see it being called once, but the duplicate PO is still getting created.
The idea I had was adding an insert business rule to the purchase order table and call the stack trace to figure out who called the insert. This might be naive, it may not be part of the stack at all.
The question then is how would I troubleshoot this? How might I determine from what avenue does an arbitrary record get inserted from?
Thanks,
Jordan
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 02:25 PM
Also, this worked for me:
try {
throw new Packages.java.lang.Throwable();
} catch (e) {
var st = e.getStackTrace();
var out = [];
for (var i = 0; i < st.length; i++)
out.push(st[i].toString());
gs.log(out.join("\n"));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 02:15 PM
First: I tested out Bernie's script on my instance and it works exactly as advertised. What are you expecting it to do? FYI - gs.print() only writes to the terminal output while operating a script in the "Scripts - Background" module and will not output anything to the actual logs in the database. For that you should use gs.log(). Does using gs.log() give you what you were expecting?
Second: Your idea is a good one. If you want to output a stack trace from the Business Rule add the following code:
try {
throw new Packages.java.lang.Throwable();
} catch (e) {
gs.log(e);
gs.log(Packages.com.glide.util.Log.getStackTrace(e));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 02:25 PM
Also, this worked for me:
try {
throw new Packages.java.lang.Throwable();
} catch (e) {
var st = e.getStackTrace();
var out = [];
for (var i = 0; i < st.length; i++)
out.push(st[i].toString());
gs.log(out.join("\n"));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 02:49 PM
Hey Matthew,
Thanks for the reply.
I should have been more clear with Bernie's script. I was executing it via business rule but receiving the following error : [java.lang.SecurityException: Illegal attempt to access class 'com.glide.util.Log' via script]
Here's the full error:
java.lang.SecurityException: Illegal attempt to access class 'com.glide.util.Log' via script
Caused by error in Business Rule: 'TestingPOStackTrace' at line 11
8: gs.log('SourceName :' + e.sourceName);
9: gs.log('Name: ' + e.name);
10: gs.log('Message : ' + e.message);
==> 11: gs.log(Packages.com.glide.util.Log.getStackTrace(e));
12: }
13: })(current, previous);
I've tried out your second solution. That seems to work for me. I'm getting n distinct stack trace dumps which I figure if I dig through I'll be able to find the route of my issue.
Thanks for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2016 04:39 PM
I need to thank you again. The stack trace helped me solve my purchase order duplication issue!