How to get the value in the date field using script include?

Yesh
Tera Contributor

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

15 REPLIES 15

Yesh
Tera Contributor

Hi @Anil Lande ,

Not getting any logged message even after using Glide Record also.

Thanks

Hitoshi Ozawa
Giga Sage
Giga Sage

Yesh,

Try surrounding with a try-catch to see if there is any error and also logging the hdate.

Also, provide explicit details on what "not working" means. It is returning null? Returning unexpected result? If so, what is expected and what is actually being returned?

try {
    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');
        gs.info('hdate:' + hdate);
        hmonth = hdate.substring(6, 7);
    }
} catch (e) {
    gs.error(e.message);
}

Hi Hitoshi,

I am not getting error. Even tried logging the hdate, the message is not getting displayed anywhere. It seems to be not getting inside the loop.

Thanks

Try returning a string as the first step to make sure the function is being called and displaying the value returned from the Script Include as the first step after calling the function.

If null is returned, it implies the function is not being called.

validateDate: function() {
return "function called";
try {
    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');
        gs.info('hdate:' + hdate);
        hmonth = hdate.substring(6, 7);
    }
} catch (e) {
    gs.error(e.message);
}

Hi,

The function is getting called.

Thanks