Get Display Value of Date field

JJG
Kilo Guru

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::

find_real_file.png

13 REPLIES 13

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.

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?

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

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

Bhagyashri Sort
Kilo Guru

Hi,

You are syntax is wrong, you have to pass the field name as a parameter to API.

 

find_real_file.png

 

find_real_file.png

Please mark it correct or make it helpful, if my response helps you.

 

Thanks

Bhagyashri Sorte