How to get the value in the date field using script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:07 AM
Hi Team,
I have a requirement like I need to get the value of a date field using script include. Here the thing is it working for one set of code and it is not working for other set of code:
The following code is working fine:
var calendar = new GlideRecordSecure('x_calendar');
calendar.addQuery('u_legal_entity', LE);//this field is a reference field to another table
calendar.query();
while(calendar.next()) {
var year = calendar.getValue('u_year');
var month = calendar.getValue('u_month');
if(year == pyear && month == pmonth){
var start = new GlideDateTime(calendar.getValue('u_me_start_date'));
var end = new GlideDateTime(calendar.getValue('u_me_end_date'));
var diff = GlideDateTime.subtract(start,end);
var mdays = diff.getRoundedDayPart();
}
}
The following code is not working:
I have used the same query as above
var holiday = new GlideRecordSecure('x_holidays');
holiday.addQuery('u_legal_entity', LE); //this field is a reference field to another table
holiday.query();
while(holiday.next()) { // It is not even getting inside the loop
hdate = holiday.getValue('u_holiday_date');
hmonth = hdate.substring(6,7);
}
Any suggestions are helpful.
I don't know where i have done a mistake. It seems to be correct code.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 03:10 AM
Hi,
didn't get this part -> get the working day of the selected date in the field
Are you saying you want to add x days to the given date by excluding holidays and weekends?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 03:27 AM
Hi,
Let us say, in a month there are 30days. In which, by excluding weekends we have 22 days and by excluding holidays, let us say we have one holiday in a month, then the no.of working days will become 21. User selects a date, if it is a weekend, then it should display as a weekend. If it is a holiday, then it should display as a holiday. If it is working day that means not a holiday or weekend, then the number of the working day should be displayed. Let us take an example like the selected date : 2022-04-08, up to this day one weekend is passed that means two days were removed, So the output is 8-2 = 6.
I hope you will get the requirement now.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:16 AM
Hi,
Looks like you have not defined LE anywhere.
holiday.addQuery('u_legal_entity', LE); // Make sure LE is defined before this like.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 02:22 AM
Hi,
LE is defined.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 03:08 AM
Hi
Please check Read ACL's written on table x_holidays, as you are using GlideRecordSecure there is is possibility of user not having access (required roles) to access this table records.
Try below with GlideRecord only.
var holiday = new GlideRecord('x_holidays');
holiday.addQuery('u_legal_entity', LE); //this field is a reference field to another table
holiday.query();
while(holiday.next()) { // It is not even getting inside the loop
hdate = holiday.getValue('u_holiday_date');
hmonth = hdate.substring(6,7);
}
Also I would suggest to use GlideRecord instead of GlideRecordSecure everywhere if you don't want to read records following security rules.
Thanks,
Anil Lande
Thanks
Anil Lande