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.

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

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

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());

}

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

LinkedIn