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 06:35 AM
firstly, I have used this 'date' field in several other business rules without issues
secondly, yes the date field name is literally 'date'
Here is the full code which works perfectly and returns the required records, the only problem is that it does not give me the display value of the date:
var grContract = new GlideAggregate('x_utsll_time_manag_hour_tracker');
grContract.addQuery('name_of_employee', name);
grContract.addQuery('date', '>=', firstOfMonth);
grContract.addQuery('date', '<=', endOfMonth);
var grOr4 = grContract.addQuery('status', 'No Approval Required');
grOr4.addOrCondition('status', 'Approved');
grContract.groupBy('contract_job'); //groups the record by contract
grContract.addAggregate('SUM', 'hours_worked'); //sums the hours
grContract.query();
while (grContract.next()) {
var date = grContract.date;
gs.info('Date: '+date);
var contract = grContract.contract_job;
var searchContract = new GlideRecord('ast_contract');
searchContract.addQuery('sys_id', contract);
searchContract.query();
if (searchContract.next()) {
var contractDes = searchContract.short_description;
}
As you can see this is a more lengthy script and is not neccisary for debug purposes, as I said previously, it returns the required records and executes properly. I just need to extract the date display value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 07:49 AM
I did some testing and it seems like its the GlideAggregate that's the problem. When I turn it into a GlideRecord it works fine. Any idea why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 07:56 AM
Hi,
As said by others earlier; any specific need to use getDisplayValue() on date field?
getDisplayValue() works well with GlideAggregate
Sample script I ran
var aggIncident = new GlideAggregate('incident');
aggIncident.addQuery('company.name','=','ACME Africa');
aggIncident.query();
while(aggIncident.next()){
gs.info('Incident is: ' + aggIncident.number + ' date is ' + aggIncident.getDisplayValue('u_sample_date') + ' Caller Id is ' + aggIncident.getDisplayValue('caller_id'));
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 06:16 AM