How to Hide a Button based on Business/Working Hours of the Assignment Group.

Abdul333
Tera Contributor

Hello All,

 

I have Requirement that to hide the UI Action button after business hours of the assignment group.

 

I created a UI Action button called "Send Reminder".

We need to show this Button based on assignment group Business hours.

Business hours are different for each assignment group, based on their location.

We have users from Worldwide.

 

Is there any possible way to implement this?

 

We have a field called Schedule, in that schedule we added the days of the week and timing.

please check the attached screenshot.

 

Abdul333_0-1691506578234.png

this is foe one assignment group, we have one functionality like if a schedule ends with JP, its for Japan, Ru for Russia like that.

Here we need hide that button after 17(5PM) and before 9AM and we need hide for saturday and sunday also.

 

please check and help us to get this implemented.

 

 

@Ankur Bawiskar @SANDEEP28 @Community Alums 

 

Thanks,

Abdul

 

 

1 ACCEPTED SOLUTION

@Abdul333 As you confirmed that SLA name and assignment group name is same then put below code in script include

 

var IncidentReminder = Class.create();
IncidentReminder.prototype = {
    initialize: function() {},

    visibilityBasedOnSchedule: function(groupName) {
        var grSla = new GlideRecord('contract_sla');
        if (grSla.get('name', groupName)) {
            var gsSchedule = new GlideSchedule(grSla.getValue('schedule'));
            var todayDateTime = new GlideDateTime();
            if (gsSchedule.isInSchedule(todayDateTime))
                return true;
            else
                return false;
        } else {
            return false;
        }
    },

    type: 'IncidentReminder'
};

 

UI action Condition -  

new global.IncidentReminder().visibilityBasedOnSchedule(current.assignment_group.getDisplayValue());

 

 If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

 

View solution in original post

16 REPLIES 16

@Abdul333   If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

@SANDEEP28 , I tried it but in our instance cmn_schedule_span table "Group" is empty because of that it is not working.

 

Abdul333_0-1691658335965.png

Having schedules in Name field like "in:Monday-Friday08.00-16.30" --for example India Mon-Fri

Can we use Name instead of GroupID?

Could you please help me on this.

 

Thanks,

Abdul

 

@Abdul333 How are you relating work schedule with assignment group ? 

Or you are not relating at all and you are simply putting identifier in Name of work schedule. If its their in Name, then it will be very complex logic we need build just to get the relevant schedule record and its not recommended. 

ServiceNow has provided schedule entry related list to link Work schedule with Assignment group. Please make use of that.

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

@SANDEEP28, Assignment group name and sla are same.

From SLA table will get the schedule(cmn_schedule.list). from schedule we get Schedule entries(cmn_schedule_span.list).

 

Instead of writing on cmn_schedule_span, we can write on cmn_schedule right.

 

I tried like this, it worked.

 

var glide = new GlideRecord('cmn_schedule');
glide.addQuery('name', 'MoFr08:00-17:00IN); //here In means for India
glide.query();
if (glide.next()) {
var sched = new GlideSchedule(glide.sys_id);
gs.log(sched);
var date = new GlideDateTime();
gs.log(date);
if (sched.isInSchedule(date))
gs.info("Is in the schedule");
else
gs.info("Is NOT in the schedule");
}

 

please help me how to write Script Include based on the above script, i think it will work and hide the button based on working hours. 

 

and i want to call two script includes in UI Action Condition.

please explain me on this.

 

 

Many Thanks,

Abdul

@Abdul333 If assignment group and schedule name is same then put below code in script include and condition in UI action.

 

Condition -  

new global.IncidentReminder().visibilityBasedOnSchedule(current.assignment_group.getDisplayValue());

var IncidentReminder = Class.create();
IncidentReminder.prototype = {
    initialize: function() {},

    visibilityBasedOnSchedule: function(groupName) {
        var grSchedule = new GlideRecord('cmn_schedule');
        if (grSchedule.get('name', groupName)) {
            var gsSchedule = new GlideSchedule(grSchedule.getUniqueValue());
            var todayDateTime = new GlideDateTime();
            if (gsSchedule.isInSchedule(todayDateTime))
                return true;
            else
                return false;
        } else {
            return false;
        }
    },

    type: 'IncidentReminder'
};

 

 If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!