Print Stacktrace without an Error

jordanburnett
Kilo Contributor

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

1 ACCEPTED SOLUTION

Mwatkins
ServiceNow Employee
ServiceNow Employee

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"));


}


View solution in original post

5 REPLIES 5

Hi,

 

I have a question on using the package calls like this (new Packages.java.lang), Service now suggests to use the glide functions instead.

 

What is your thought on this?

 

Thanks

Yogesh