- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2020 03:40 PM
Hello,
I have a script include that searches a table. It should pull records if the 'pay_period_end' date field is greater than or equal to today's date. It doesn't seem to work, is there an error? It works when I remove my grPayPeriod.addQuery line.
get_payPeriod: function() {
var dateToday = new GlideDate();
var grPayPeriod = new GlideRecord('x_utsll_time_manag_hour_tracker');
grPayPeriod.addQuery('pay_period_end' >= dateToday);
grPayPeriod.query();
if (grPayPeriod.next()) {
return grPayPeriod.getValue('pay_period');
}
},
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2020 05:30 PM
Use below code
get_payPeriod: function() {
var dateToday = new GlideDate();
var grPayPeriod = new GlideRecord('x_utsll_time_manag_hour_tracker');
grPayPeriod.addQuery('pay_period_end', ">=",dateToday);
grPayPeriod.query();
if (grPayPeriod.next()) {
return grPayPeriod.getValue('pay_period');
}
Also, check useful blog for date field validations.
https://community.servicenow.com/community?id=community_blog&sys_id=467c62e1dbd0dbc01dcaf3231f9619ad
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2020 05:31 PM
Easiest way is to build query on the list view of the table and add copied query in addEncodedQuery.
ServiceNow will take care of rest for you.
Try this code-
get_payPeriod: function() {
var grPayPeriod = new GlideRecord('x_utsll_time_manag_hour_tracker');
grPayPeriod.addQuery('pay_period_end>=javascript:gs.beginningOfToday()');
grPayPeriod.query();
if (grPayPeriod.next()) {
return grPayPeriod.getValue('pay_period');
}
},
-Tanaji
Please mark reply correct/helpful if applicable.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2020 11:30 PM
Hi JJG,
Can you perform the same query from a list? If so, you could use the breadcrumb too your advantage. Copying that breadcrumb, and using it in your script. Read about this in an article I wrote a while back:
Utilizing the breadcrumb on lists to generate your query
Looking at your script further. You do mention querying for records. So multiple records? While you performing an if, so actually only one record? Now you will only get one records. It also does not have an order or something, so which records actually?
So is this correct?
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