Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get encoded query display value

lucky6
Tera Contributor

Hi Everyone,

I want to get date time fields display values so how can i get it in encoded query .

Example: opened on today

opened_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()

12 REPLIES 12

Hi,

So you are applying query to your table then which display value you want to fetch for which field?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

opened and closed dates

Hi,

updated script below

Ensure you give proper field name, table name etc

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

var arr = [];

var table = 'table',
var gr = new GlideRecord(table);
gr.addQuery('opened_atONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
gr.query();
while(gr.next()) {
var fields = {};
fields.Number = gr.number + '';
fields.Opened = gr.opened_at.getDisplayValue();
fields.Closed = gr.closed_at.getDisplayValue();
arr.push(fields);
}

response.setStatus(200);
response.setBody(arr);

})(request, response);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

HI,

I got your point here but i want query string display value , but here you are sending those fields in respsonse .

Hi,

How is the API being consumed?

I didn't get your point on you want display value of the query string.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader