- 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: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:33 PM
This wont give proper results because of time difference.
GlideDate() will give you date in your timezone whereas the fields value in the backend is in GMT.
-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 06:10 PM
You can't assume that since you don't know poster's instance.
I was correcting typo in his code.
Anyway, blog has solution to validate date fields.
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2020 06:50 PM
I understand you corrected typo and I really appreciate helping others.
Having said that you can't assume poster is a male;)
-Tanaji
Please mark reply correct/helpful if applicable