Need to return public holiday value

Nitesh Kumar5
Tera Contributor

Hi Team,

 

I have a catalog item named annual leave where I have configured few field like requestor which is populating current logged in information ,Start date (date time type) and End date(date time type) and how many public holidays days selected (single text) type field.

Now suppose if I select start date and end date and between start date and end if there are 3 public holdays  configured in cmn_schedule table for the selected requestor then as per the requirement it will return 3 days in how many public holidays field on the form .

I have written one script include and using the script include in client script but I am not getting the proper output (from client script  I am passing the value of requestor location , start date and end date) .

2 REPLIES 2

Chandra18
Mega Sage

Hi @Nitesh Kumar5 
1.Have to check client callable button on script include.
2.Provide the log in script include and try to find problem.

3. if script include is passing right response then Provide alert in client script to consolidate problem in script.

Could you please provide script include & Client script to validate.

Thank you!

 

Hi @Chandra18 

I have written below given code and it is working properly for few scenarios but for one scenario it's failing when I select start date as a public holiday and end date as a again public holiday(same date) then it is always returning 0 which should have retruned 1 and i tried to fix the code by checking day==0 and incrmenting by 1 but that is also not working and generation few more issue. 

getpublicholidays: function(start_date, end_date, requestor) {
var location;

//var grovide me the solution.1 = new GlideDateTime(this.getParameter('start_date'));

//var g2 = new GlideDateTime(this.getParameter('end_date'));
//var user=this.getParameter('requestor');
var userInfo = new GlideRecord('sys_user');
userInfo.addActiveQuery();
userInfo.addQuery('sys_id', user);
userInfo.query();

if (userInfo.next()) {
location = userInfo.location.getDisplayValue();
}
var scheduleId;
if (location == "some value") {
//
scheduleId = 'value from cmn_schedule table';

}

var res;
var no;
var plannedTaskAPI = new SNC.PlannedTaskAPI();
var resp = plannedTaskAPI.calculateDuration(gd1, gd2, scheduleId);
var response = new JSON().decode(resp);
var duration = response.duration;
var dur = duration.split('00');
var day = dur[0];
return day;


}