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 04:52 AM
If the function is getting and the while loop is skipped, it implied the query is not retrieving any records. As I've asked earlier, adding a log statement to output a string as the first step in the while loop should log something out. If there's no log, it implies a problem with the query statement.
BTW, what is the type of variable 'u_holida_date'? Is it a string? If it's GlideDateTime, should do a hdate.toString() to convert is into a string before doing .substring(6,7). Also, it's better to use .getMonth() to get month.