Script Help to exclude weekends
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2023 01:21 AM
I have a custom True/False field, i wanted to make the field set as true when the Assignment Group for the case is empty for more than 1 business days..
Someone please help how to achieve this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2023 03:03 AM
Hi Jyoti,
Please try below code in scheduled job, value of iDay 6 and 7 are referring
- 6 = Saturday
- 7 = Sunday
var grCase = new GlideRecord('<TABLE_NAME>');
grCase.addEncodedQuery('active=true^assignment_group=NULL');
grCase.query();
while(grCase.next()){
var gdtCreated = new GlideDateTime(grCase.getValue('sys_created_on'));
var bIsWorkingDay = false;
do {
var iDay = gdtCreated.getDayOfWeekLocalTime();
gdtCreated.addDaysLocalTime(1);
if((iDay!=6) && (iDay!=7)){
bIsWorkingDay = true;
}
} while (!bIsWorkingDay);
var gdtCurrent = new GlideDateTime();
//gs.print(gdtCreated);
//gs.print(gdtCurrent);
if(gdtCreated < gdtCurrent) {
grCase.setValue('CUSTOM_FIELD_NAME', true);
grCase.update();
}
}
Regards,
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2023 04:10 AM
Hi @Baala T : Thanks for sharing the script, what if the case got created on weekend and group was empty (example on Saturday).. so on Tuesday(More than 1 business days) it will make the field set as true right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2023 04:42 AM
Modified the script little bit. PFB
var gdtCreated = new GlideDateTime('2023-06-02 09:27:56');
gs.print('Actual Created Date & Time : ' + gdtCreated);
var bIsWorkingDay = false;
var bCheckCreatedInNonBusinessDays = false;
do {
var iCreatedDay = gdtCreated.getDayOfWeekLocalTime();
if(!bCheckCreatedInNonBusinessDays){
//Is it created on Saturday
if (iCreatedDay==6){
gdtCreated.addDaysLocalTime(1);
}
//Check if it is falls on Sunday
iCreatedDay = gdtCreated.getDayOfWeekLocalTime();
if (iCreatedDay==7){
gdtCreated.addDaysLocalTime(1);
}
bCheckCreatedInNonBusinessDays = true;
gs.print('Business Start Date & Time : ' + gdtCreated);
}
//Add a Business Day
gdtCreated.addDaysLocalTime(1);
var iBusinessDay = gdtCreated.getDayOfWeekLocalTime();
gs.print(iBusinessDay + '<>' + gdtCreated)
if((iBusinessDay!=6) && (iBusinessDay!=7)) {
bIsWorkingDay = true;
}
} while (!bIsWorkingDay);
var gdtCurrent = new GlideDateTime();
gs.print('Business End Date & Time : ' + gdtCreated);
gs.print('Current Date & Time : ' + gdtCurrent);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 02:34 AM
@Baala T :
it is not make the Custom field to set it as true when Assignment group is empty for more than 1 business days, please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2023 03:04 AM
Hope you have created as a scheduled job, What is the error that you are getting?
Let me know the Table Name and Field Name.