Get Display Value of Date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 05:31 AM
Hello,
I am using a business rule to pull the value of a date field called 'date'. I am trying to get its display value but am hitting some difficulties. What am I missing?
var grContract = new GlideAggregate('x_utsll_time_manag_hour_tracker');
grContract.addQuery('name_of_employee', name);
grContract.query();
while (grContract.next()) {
var date = grContract.date.getDisplayValue();
gs.info('Date: '+date);
}
Output::

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 05:46 AM
Hi JJG,
If you just use grContract.date, do you get a valid date then?
What's the reason for using .getDisplayValue? Is this because you for example want the stored date in the timezone of a logged in user?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 05:47 AM
This Developer page might help you also, good info on the GlideDate API.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideDateScope...
Also this example:
var gd =new GlideDate();
gd.setValue('2015-01-01');
gs.info(gd.getDisplayValue());​
You might use it in your case like:
var gd = new GlideDate();
gd.setValue(grContract.date);
gs.info(gd.getDisplayValue());​
(this works for Global and also Scoped)
So wrapped into your code...
var grContract = new GlideAggregate('x_utsll_time_manag_hour_tracker');
grContract.addQuery('name_of_employee', name);
grContract.query();
while (grContract.next()) {
var date = new GlideDate();
date.setValue(grContract.date);
gs.info('Date: ' + date.getDisplayValue());
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 06:11 AM
I updated my code to your suggestion and am still getting the same output
var grContract = new GlideAggregate('x_utsll_time_manag_hour_tracker');
grContract.addQuery('name_of_employee', name);
grContract.query();
while (grContract.next()) {
var date = new GlideDate();
date.setValue(grContract.date);
gs.info('Date: ' + date.getDisplayValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 06:18 AM
So did you also debug grContract.date and nothing else? Is that already working or not?
Your log message did got trigger right, so than it's not a query issue.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field