Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Readable Query from GlideRecord.getEncodedQuery

Luke Van Epen
Tera Guru

Hi All,

In my scoped app I have a logging system for debugging etc, that regularly outputs an encoded query to say "Found x number of records matching condition y" in combination with other things.

Is there a way to take arbitrary GlideRecord.getEncodedQuery and format it into the human-readable version?

I know you can use getDisplayValue on a conditions field, but this will not be stored in any field. I've tried hijacking the ATFStepDescriptionGenerator().getConditionDescription however this doesn't work, neither does the one that auto-generates PA Indicator descriptions.

 

6 REPLIES 6

asifnoor
Kilo Patron

Hi Luke,

yes, you can do like below.

gs.info(new GlideQueryBreadcrumbs().getReadableQuery('incident','active=true^assignment_group=b85d44954a3623120004689b2d5dd60a^state=1'));

//replace incident with your table name and the 2nd param should contain the full encoded query.

And the output will be like below

*** Script: Active = true .and. Assignment group = CAB Approval .and. State = New

Mark the comment as a correct answer and also helpful if it helps.

 

 

That is definitely helpful for when I log things in Global, however for my scoped app i get the below error:

 

Exception (java.lang.SecurityException: GlideQueryBreadcrumbs is not allowed in scoped applications) 

You can use this hack:

var gr = new GlideRecord('asmt_metric_category');
gr.initialize();
gr.table = 'incident';
gr.filter = 'active=true^assignment_group=b85d44954a3623120004689b2d5dd60a^state=1';
gr.getDisplayValue('filter'); 
Active = true .and. Assignment group = CAB Approval .and. State = New

This table has a condition field with the readable=true attribute, which displays conditions in a readable format.

You could use this on a field on your scoped app if you wanted.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Hi,

For this you need to write a script include (make this script include accessible from all application scopes) and call this script include from your scoped app like below. 

new Log_Scoped_App().readQuery('incident','active=true^assignment_group=b85d44954a3623120004689b2d5dd60a^state=1');

And script include is like below. (refer to below code and attached screenshot)

var Log_Scoped_App = Class.create();
Log_Scoped_App.prototype = {
    initialize: function() {
    },
    readQuery: function(tableName,encodedQuery) {
	  gs.info(new GlideQueryBreadcrumbs().getReadableQuery(tableName,encodedQuery));	
	},
    type: 'Log_Scoped_App'
};

 

find_real_file.png

 

Kindly mark the comment as a correct answer and also helpful once worked.