Debugging sql statements that run within script as gliderecord

Inya
Tera Contributor

Hi All,

There is a need to debug SQL statements that are executed within a scriptinclude / transform map's onbefore script for the purpose of facilating indexing via database.

However on node logs  / debug sql during execution - the gliderecord classes used within script include and onbefore script are not getting displayed. Could you help here.

 

Example : lets say i have a bunch of gliderecord operations done on my SI and other scripts that must get displayed as SQL statement for facilitating DB team.

var gr = new GlideRecord("<table>");
gr.addQuery('<column>',par1);//added recent
gr.orderBy('usr');
gr.query();


while (gr.next()) {
//code
}

Thanks,

Iniya

@asifnoor  For your kind perusal, if you can help here. thanks Asif.

3 REPLIES 3

Nitesh Alashe1
Giga Expert

Hello Inya,

 

Instead of addQuery() can you try using addEncodedQuery() and then you can print the query with getEncodedQuery() where you are suppose to check/debug the data you getting in query.

 

BR

Nitesh

If my answer helped you in any way, mark answer as helpful and correct.

 

 

asifnoor
Kilo Patron

Hello Iniya,

Go to session debug and enable all and check once. Check this link for more information.

https://docs.servicenow.com/bundle/orlando-application-development/page/script/debugging/concept/c_S...

Regards,

Asif

Siddhnath Pande
Mega Guru

Hi Inya,

I would recommend use background Script module which you will find in System definition application run the script there first.

or else you can filter the record in list & copy the query from there & put in encoddedquery() method.

So this is two way by which you can debug your script or Sql Statement.

If the above code helps then please mark my answer Correct and Helpful.

Thanks and Regards:
Siddhnath Pandey