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

Don't know if this is your full code, if it is indeed your fullcode. Can you also double check:

grContract.addQuery('name_of_employee', name);

==> name.

What is name here?

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

LinkedIn

I did some testing and it seems like its the GlideAggregate thats the problem. When I turn it into a GlideRecord it works fine. Any idea why?

Tanushree Doiph
Mega Guru

Hey,

Try this code,

var date =  gr.Contract.getDisplayValue('date');

Thanks

Tanushree

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why you require displayValue() on date field? if you use grContract.date it should directly give you the value

you can use this syntax; use proper field name for "date" inside the getDisplayValue() method

var date = grContract.getDisplayValue('date');

gs.info('Date: ' + date);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Allen Andreas
Administrator
Administrator

Hello,

This type of thing causes a thread to go all out of control heh...

So firstly, you are using a variable name, like 'date', which can be possibly reserved by the system...so I'd personally recommend you use other types of variable names and not stuff like "date, answer, return" which could be used by the system or JavaScript in other ways. That's just my opinion...but from experience, it helps cause something small like this to not even be a concern or possibility of an issue.

Secondly, is your field named "date", literally, on this table: x_utsll_time_manag_hour_tracker

What else in your script are you not showing here? As you're using "name" in your addQuery and from your code provided, to us, name is not defined.

I'd recommended checking those things over and seeing if you have better results.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!